File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ const TPL = @import("v8.zig").TPL;
22
22
// Utils functions
23
23
// ---------------
24
24
25
+ const JSError = error {
26
+ InvalidArgument ,
27
+ };
28
+
25
29
fn throwBasicError (msg : []const u8 , isolate : v8.Isolate ) v8.Value {
26
30
const except_msg = v8 .String .initUtf8 (isolate , msg );
27
31
const exception = v8 .Exception .initError (except_msg );
@@ -36,6 +40,11 @@ fn throwError(
36
40
err : anyerror ,
37
41
isolate : v8.Isolate ,
38
42
) v8.Value {
43
+ // well known error.
44
+ switch (err ) {
45
+ JSError .InvalidArgument = > return throwTypeError ("invalid argument" , isolate ),
46
+ else = > {},
47
+ }
39
48
const ret = func .return_type ;
40
49
41
50
// Is the returned Type a custom Exception error?
@@ -136,10 +145,9 @@ fn getNativeArg(
136
145
if (comptime arg_T .underOpt () != null ) {
137
146
return null ;
138
147
}
139
- // TODO: else return error "Argument x is not an object"
140
148
}
141
149
142
- if (! js_value .isObject ()) unreachable ; // TODO: throw js exception
150
+ if (! js_value .isObject ()) return JSError . InvalidArgument ;
143
151
144
152
// JS object
145
153
const ptr = getNativeObject (
Original file line number Diff line number Diff line change @@ -293,8 +293,7 @@ pub fn exec(
293
293
// not.
294
294
// https://github.com/lightpanda-io/jsruntime-lib/issues/185
295
295
var bug_native_obj = [_ ]tests.Case {
296
- .{ .src = "let car = new Car();" , .ex = "undefined" },
297
- .{ .src = "car.changeBrand('foo');" , .ex = "true" },
296
+ .{ .src = "try { car.changeBrand('foo'); false; } catch(e) { e instanceof TypeError; }" , .ex = "true" },
298
297
};
299
298
try tests .checkCases (js_env , & bug_native_obj );
300
299
}
You can’t perform that action at this time.
0 commit comments