Skip to content

Commit f806259

Browse files
committed
Added assertion to verify object is tensor
1 parent f3ba749 commit f806259

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extension/wasm/wasm_bindings.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ EValue to_evalue(val v) {
384384
return EValue(v.as<int64_t>());
385385
} else if (type_str == "object") {
386386
// If it is an object, assume it is a tensor.
387+
THROW_IF_FALSE(
388+
v.instanceof
389+
(val::module_property("Tensor")),
390+
"Received non-tensor object: %s",
391+
val::global("JSON").call<std::string>("stringify", v).c_str());
387392
return EValue(v.as<JsTensor&>().get_tensor());
388393
}
389394
THROW_JS_ERROR(
@@ -696,9 +701,10 @@ EMSCRIPTEN_BINDINGS(WasmBindings) {
696701
// Additionally, different enums of the same type are considered to be equal.
697702
// Assigning the name field fixes both of these issues.
698703
#define JS_ASSIGN_SCALAR_TYPE_NAME(T, NAME) \
699-
EM_ASM(Module.ScalarType.NAME.name = #NAME);
704+
val::module_property("ScalarType")[#NAME].set("name", #NAME);
700705
JS_FORALL_SUPPORTED_TENSOR_TYPES(JS_ASSIGN_SCALAR_TYPE_NAME)
701-
#define JS_ASSIGN_TAG_NAME(NAME) EM_ASM(Module.Tag.NAME.name = #NAME);
706+
#define JS_ASSIGN_TAG_NAME(NAME) \
707+
val::module_property("Tag")[#NAME].set("name", #NAME);
702708
EXECUTORCH_FORALL_TAGS(JS_ASSIGN_TAG_NAME)
703709
}
704710

0 commit comments

Comments
 (0)