Skip to content

Commit 784bd85

Browse files
committed
[js] Implement nqp::getlexcaller.
1 parent 6010bd6 commit 784bd85

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/vm/js/Operations.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ class QAST::OperationsJS {
12921292
}
12931293

12941294
add_simple_op('getlexdyn', $T_OBJ, [$T_STR], sub ($name) {"{$*CTX}.lookupDynamicFromCaller($name)"});
1295+
add_simple_op('getlexcaller', $T_OBJ, [$T_STR], sub ($name) {"{$*CTX}.lookupFromSomeCaller($name)"});
12951296
add_simple_op('getlexrel', $T_OBJ, [$T_OBJ, $T_STR]);
12961297

12971298
add_simple_op('captureexistsnamed', $T_INT, [$T_OBJ, $T_STR]);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ Ctx.prototype.lookupDynamicFromCaller = function(name) {
272272
nqp code usually fallbacks to looking up of global */
273273
};
274274

275+
Ctx.prototype.lookupFromSomeCaller = function(name) {
276+
var currentCallerCtx = this.caller;
277+
while (currentCallerCtx) {
278+
var currentCtx = currentCallerCtx;
279+
while (currentCtx) {
280+
if (currentCtx.hasOwnProperty(name)) {
281+
return currentCtx[name];
282+
}
283+
currentCtx = currentCtx.outer;
284+
}
285+
currentCallerCtx = currentCallerCtx.caller;
286+
}
287+
return null;
288+
};
289+
275290
Ctx.prototype.lookup = function(name) {
276291
var ctx = this;
277292
while (ctx) {

0 commit comments

Comments
 (0)