Skip to content

Commit bbfb1bd

Browse files
committed
[js] Implement method_not_found_error
1 parent 75c7430 commit bbfb1bd

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

src/vm/js/Compiler.nqp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
998998
Chunk.void(|@capture_inners);
999999
}
10001000

1001-
method compile_block(QAST::Block $node, $outer, $outer_loop, :$want, :@extra_args=[]) {
1001+
method compile_block(QAST::Block $node, $outer, $outer_loop, :$want, :@extra_args=[], :$hll) {
10021002

10031003
my str $outer_ctx := try $*CTX // "null";
10041004

@@ -1033,7 +1033,8 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
10331033

10341034

10351035
my $outer_ctx := $has_closure_template ?? "this.outerCtx" !! ($*BLOCK.outer ?? $*BLOCK.outer.ctx !! 'null');
1036-
my str $create_ctx := "var $*CTX = new nqp.Ctx(caller_ctx, $outer_ctx, this);\n";
1036+
my str $create_ctx := "var $*CTX = new nqp.Ctx(caller_ctx, $outer_ctx, this);\n"
1037+
~ ($hll ?? "$*CTX.\$\$hll = nqp.getHLL({quote_string($hll)});\n" !! '');
10371038

10381039
%*USED_CTXS{$*CTX} := 0;
10391040

@@ -1311,7 +1312,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
13111312
"var sh = nqp.createArray([{nqp::join(',',@sh)}]);\n"
13121313
~ "var sc = nqp.op.createsc({quote_string(nqp::scgethandle($sc))});\n"
13131314
~ self.emit_code_refs_list($ast)
1314-
, "nqp.op.deserialize($quoted_data,sc,sh,code_refs,null,cuids,function() \{{self.setup_wvals}\});\n"
1315+
, "nqp.op.deserialize({quote_string($*HLL)}, $quoted_data,sc,sh,code_refs,null,cuids,function() \{{self.setup_wvals}\});\n"
13151316
~ "nqp.op.scsetdesc(sc,{quote_string(nqp::scgetdesc($sc))});\n");
13161317
}
13171318

@@ -1439,7 +1440,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
14391440
self.mark_serializable($node[0]);
14401441

14411442
# Compile the block.
1442-
my $block_js := self.as_js($node[0], :want(($instant && nqp::defined($node.main)) ?? $T_VOID !! $T_OBJ));
1443+
my $block_js := self.compile_block($node[0], $*BLOCK, $*LOOP, :hll($node.hll), :want(($instant && nqp::defined($node.main)) ?? $T_VOID !! $T_OBJ));
14431444

14441445
my @post;
14451446
for $node.post_deserialize -> $node {
@@ -1950,6 +1951,8 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
19501951

19511952
my $*COMPUNIT;
19521953

1954+
my $*LOOP;
1955+
19531956
my $compile_block := -> {self.as_js($ast, :want($instant ?? $T_VOID !! $T_OBJ))};
19541957

19551958
my $chunk := nqp::istype($ast, QAST::CompUnit) ??

src/vm/js/Operations.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class QAST::OperationsJS {
648648
add_simple_op('serialize', $T_STR, [$T_OBJ, $T_OBJ], :side_effects);
649649
add_simple_op('scobjcount', $T_INT, [$T_OBJ]);
650650
add_simple_op('createsc', $T_OBJ, [$T_STR], :side_effects);
651-
add_simple_op('deserialize', $T_OBJ, [$T_STR, $T_OBJ, $T_OBJ, $T_OBJ, $T_OBJ], :side_effects);
651+
add_simple_op('deserialize', $T_OBJ, [$T_STR, $T_OBJ, $T_OBJ, $T_OBJ, $T_OBJ], :side_effects, :hll);
652652
add_simple_op('scsetobj', $T_OBJ, [$T_OBJ, $T_INT, $T_OBJ], :side_effects);
653653
add_simple_op('scgetobj', $T_OBJ, [$T_OBJ, $T_INT], :side_effects);
654654
add_simple_op('scsetcode', $T_OBJ, [$T_OBJ, $T_INT, $T_OBJ], :side_effects);

src/vm/js/nqp-runtime/ctx.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ class Ctx extends NQPObject {
297297
return this.$$outer.lookup(name);
298298
}
299299

300+
$$getHLL() {
301+
var ctx = this;
302+
while (ctx) {
303+
if (ctx.$$hll) {
304+
return ctx.$$hll;
305+
}
306+
ctx = ctx.$$outer;
307+
}
308+
}
309+
300310
$$atkey(key) {
301311
return this.lookup(key);
302312
}

src/vm/js/nqp-runtime/deserialization.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports.wval = function(handle, idx) {
4343
return serializationContexts[handle].rootObjects[idx];
4444
};
4545

46-
op.deserialize = function(blob, sc, sh, codeRefs, conflict, cuids, setupWVals) {
46+
op.deserialize = function(hllName, blob, sc, sh, codeRefs, conflict, cuids, setupWVals) {
4747
var buffer = new Buffer(blob, 'base64');
4848
sc.codeRefs = codeRefs.array;
4949

@@ -56,7 +56,7 @@ op.deserialize = function(blob, sc, sh, codeRefs, conflict, cuids, setupWVals) {
5656
sh = sh.array;
5757
var cursor = new BinaryCursor(buffer, 0, sh, sc);
5858

59-
cursor.deserialize(sc, cuids, setupWVals);
59+
cursor.deserialize(sc, cuids, setupWVals, hll.getHLL(hllName));
6060
};
6161

6262
op.createsc = function(handle) {
@@ -512,7 +512,7 @@ class BinaryCursor {
512512
Resolve the static variables in all CodeRefs contained in cuids
513513
*/
514514

515-
deserialize(sc, cuids, setupWVals) {
515+
deserialize(sc, cuids, setupWVals, currentHLL) {
516516
var version = this.I32();
517517

518518
this.sc = sc;
@@ -643,7 +643,7 @@ class BinaryCursor {
643643

644644
for (var i = 0; i < contexts.length; i++) {
645645
if (contexts[i].outer == 0) {
646-
this.deserializeCtx(contexts[i], null);
646+
this.deserializeCtx(contexts[i], null, currentHLL);
647647
}
648648
}
649649

@@ -754,7 +754,7 @@ class BinaryCursor {
754754
}
755755
}
756756

757-
deserializeCtx(context, outerCtx) {
757+
deserializeCtx(context, outerCtx, currentHLL) {
758758
var callerCtx = null;
759759

760760
// TODO - think if we should set codeObj
@@ -771,7 +771,7 @@ class BinaryCursor {
771771
}
772772

773773
for (var inner of context.inner) {
774-
this.deserializeCtx(inner, ctx);
774+
this.deserializeCtx(inner, ctx, currentHLL);
775775
}
776776

777777
for (var closure of context.closures) {

src/vm/js/nqp-runtime/reprs.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ function noopCompose(obj, reprInfo) {
3838
}
3939

4040

41+
42+
function methodNotFoundError(ctx, obj, name) {
43+
let handler = ctx ? ctx.$$getHLL().get('method_not_found_error') : undefined;
44+
if (handler === undefined) {
45+
throw new NQPException("Cannot find method '" + name + "' on object of type " + obj._STable.debugName);
46+
} else {
47+
handler.$$call(ctx, null, obj, name);
48+
}
49+
}
50+
4151
function basicConstructor(STable) {
4252
var objConstructor = function() {};
4353
var handler = {};
@@ -50,20 +60,27 @@ function basicConstructor(STable) {
5060
}
5161
}
5262

53-
if (STable.modeFlags & constants.METHOD_CACHE_AUTHORITATIVE) {
54-
return undefined;
55-
}
56-
5763
/* are we trying to access an internal property? */
5864
if (name.substr(0, 2) === '$$') {
5965
return undefined;
6066
}
6167

68+
if (STable.modeFlags & constants.METHOD_CACHE_AUTHORITATIVE) {
69+
return function(ctx, _NAMED, obj) {
70+
methodNotFoundError(ctx, obj, name);
71+
};
72+
}
73+
74+
6275
return function() {
6376
let how = this._STable.HOW;
6477

6578
var method = how.find_method(null, null, how, this, name);
6679

80+
if (method === Null) {
81+
methodNotFoundError(arguments[0], arguments[2], name);
82+
}
83+
6784
var args = [];
6885
for (var i = 0; i < arguments.length; i++) {
6986
args.push(arguments[i]);

src/vm/js/nqp-runtime/runtime.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,5 @@ exports.paramcheckfailed = function(hllName, args) {
437437
};
438438

439439
exports.NativeRef = require('./reprs.js').NativeRef;
440+
441+
exports.getHLL = hll.getHLL;

src/vm/js/nqp-runtime/sixmodel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function findMethod(ctx, obj, name) {
2323
}
2424
}
2525

26-
if (obj._STable.HOW.find_method) {
26+
if (obj._STable.HOW.$$can(ctx, 'find_method')) {
2727
return obj._STable.HOW.find_method(ctx, null, obj._STable.HOW, obj, name);
2828
} else {
2929
return Null;
@@ -93,7 +93,7 @@ class STable {
9393

9494
var HOW = this._STable.HOW;
9595
/* This "hack" is stolen from the JVM */
96-
if (!HOW.type_check) {
96+
if (!HOW.$$can(ctx, 'type_check')) {
9797
return 0;
9898
}
9999

0 commit comments

Comments
 (0)