File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -723,6 +723,12 @@ fn getNativeObject(
723
723
obj_ptr .* = T {};
724
724
} else {
725
725
// retrieve the zig object from it's javascript counterpart
726
+
727
+ // check if the js object has a least one internal field.
728
+ if (js_obj .internalFieldCount () == 0 ) return JSError .InvalidArgument ;
729
+
730
+ // TODO ensure the js object corresponds to the expected native type.
731
+
726
732
const ext = js_obj .getInternalField (0 ).castTo (v8 .External ).get ().? ;
727
733
if (comptime T_refl .is_mem_guarantied ()) {
728
734
// memory is fixed
Original file line number Diff line number Diff line change @@ -289,11 +289,15 @@ pub fn exec(
289
289
};
290
290
try tests .checkCases (js_env , & separate_cases );
291
291
292
- // Test for the bug #185: native func expects a object but the js value is
293
- // not.
294
- // https://github.com/lightpanda-io/jsruntime-lib/issues/185
295
292
var bug_native_obj = [_ ]tests.Case {
293
+ // Test for the bug #185: native func expects a object but the js value is
294
+ // not.
295
+ // https://github.com/lightpanda-io/jsruntime-lib/issues/185
296
296
.{ .src = "try { car.changeBrand('foo'); false; } catch(e) { e instanceof TypeError; }" , .ex = "true" },
297
+ // Test for the bug #187: native func expects a native object but the js value is
298
+ // not.
299
+ // https://github.com/lightpanda-io/jsruntime-lib/issues/187
300
+ .{ .src = "try { car.changeBrand({'foo': 'bar'}); false; } catch(e) { e instanceof TypeError; }" , .ex = "true" },
297
301
};
298
302
try tests .checkCases (js_env , & bug_native_obj );
299
303
}
You can’t perform that action at this time.
0 commit comments