@@ -2580,11 +2580,11 @@ Handle<Object> CanonicalizeSmi(Handle<Object> smi, Isolate* isolate) {
25802580
25812581namespace wasm {
25822582MaybeHandle<Object> JSToWasmObject (Isolate* isolate, Handle<Object> value,
2583- ValueType expected_canonical ,
2583+ ValueType expected, uint32_t canonical_index ,
25842584 const char ** error_message) {
2585- DCHECK (expected_canonical .is_object_reference ());
2586- if (expected_canonical .kind () == kRefNull && IsNull (*value, isolate)) {
2587- switch (expected_canonical .heap_representation ()) {
2585+ DCHECK (expected .is_object_reference ());
2586+ if (expected .kind () == kRefNull && IsNull (*value, isolate)) {
2587+ switch (expected .heap_representation ()) {
25882588 case HeapType::kStringViewWtf8 :
25892589 *error_message = " stringview_wtf8 has no JS representation" ;
25902590 return {};
@@ -2602,7 +2602,7 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
26022602 return {};
26032603 default : {
26042604 HeapType::Representation repr =
2605- expected_canonical .heap_representation_non_shared ();
2605+ expected .heap_representation_non_shared ();
26062606 bool is_extern_subtype =
26072607 repr == HeapType::kExtern || repr == HeapType::kNoExtern ||
26082608 repr == HeapType::kExn || repr == HeapType::kNoExn ;
@@ -2611,7 +2611,7 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
26112611 }
26122612 }
26132613
2614- switch (expected_canonical .heap_representation_non_shared ()) {
2614+ switch (expected .heap_representation_non_shared ()) {
26152615 case HeapType::kFunc : {
26162616 if (!(WasmExternalFunction::IsWasmExternalFunction (*value) ||
26172617 WasmCapiFunction::IsWasmCapiFunction (*value))) {
@@ -2707,24 +2707,24 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
27072707 }
27082708 default : {
27092709 auto type_canonicalizer = GetWasmEngine ()->type_canonicalizer ();
2710+ DCHECK_NE (canonical_index, kInvalidCanonicalIndex );
27102711
27112712 if (WasmExportedFunction::IsWasmExportedFunction (*value)) {
27122713 Tagged<WasmExportedFunction> function =
27132714 WasmExportedFunction::cast (*value);
27142715 uint32_t real_type_index = function->shared ()
27152716 ->wasm_exported_function_data ()
27162717 ->canonical_type_index ();
2717- if (!type_canonicalizer->IsCanonicalSubtype (
2718- real_type_index, expected_canonical. ref_index () )) {
2718+ if (!type_canonicalizer->IsCanonicalSubtype (real_type_index,
2719+ canonical_index )) {
27192720 *error_message =
27202721 " assigned exported function has to be a subtype of the "
27212722 " expected type" ;
27222723 return {};
27232724 }
27242725 return handle (WasmExternalFunction::cast (*value)->func_ref (), isolate);
27252726 } else if (WasmJSFunction::IsWasmJSFunction (*value)) {
2726- if (!WasmJSFunction::cast (*value)->MatchesSignature (
2727- expected_canonical.ref_index ())) {
2727+ if (!WasmJSFunction::cast (*value)->MatchesSignature (canonical_index)) {
27282728 *error_message =
27292729 " assigned WebAssembly.Function has to be a subtype of the "
27302730 " expected type" ;
@@ -2733,7 +2733,7 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
27332733 return handle (WasmExternalFunction::cast (*value)->func_ref (), isolate);
27342734 } else if (WasmCapiFunction::IsWasmCapiFunction (*value)) {
27352735 if (!WasmCapiFunction::cast (*value)->MatchesSignature (
2736- expected_canonical. ref_index () )) {
2736+ canonical_index )) {
27372737 *error_message =
27382738 " assigned C API function has to be a subtype of the expected "
27392739 " type" ;
@@ -2748,8 +2748,8 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
27482748 WasmInstanceObject::cast (type_info->instance ())->module ();
27492749 uint32_t real_canonical_index =
27502750 real_module->isorecursive_canonical_type_ids [real_idx];
2751- if (!type_canonicalizer->IsCanonicalSubtype (
2752- real_canonical_index, expected_canonical. ref_index () )) {
2751+ if (!type_canonicalizer->IsCanonicalSubtype (real_canonical_index,
2752+ canonical_index )) {
27532753 *error_message = " object is not a subtype of expected type" ;
27542754 return {};
27552755 }
@@ -2766,14 +2766,13 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
27662766MaybeHandle<Object> JSToWasmObject (Isolate* isolate, const WasmModule* module ,
27672767 Handle<Object> value, ValueType expected,
27682768 const char ** error_message) {
2769- ValueType expected_canonical = expected;
2770- if (expected_canonical.has_index ()) {
2771- uint32_t canonical_index =
2772- module ->isorecursive_canonical_type_ids [expected_canonical.ref_index ()];
2773- expected_canonical = ValueType::RefMaybeNull (
2774- canonical_index, expected_canonical.nullability ());
2775- }
2776- return JSToWasmObject (isolate, value, expected_canonical, error_message);
2769+ uint32_t canonical_index = kInvalidCanonicalIndex ;
2770+ if (expected.has_index ()) {
2771+ canonical_index =
2772+ module ->isorecursive_canonical_type_ids [expected.ref_index ()];
2773+ }
2774+ return JSToWasmObject (isolate, value, expected, canonical_index,
2775+ error_message);
27772776}
27782777
27792778Handle<Object> WasmToJSObject (Isolate* isolate, Handle<Object> value) {
0 commit comments