Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] Add a hack to allow calling a codeRef whose closure hasn't been …
…captured yet.

This replaces the hack which twisted the closure model.
This should be done properly but is a step in the right direction.
  • Loading branch information
pmurias committed Nov 21, 2015
1 parent b5008ad commit 0d93c7c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/vm/js/nqp-runtime/code-ref.js
Expand Up @@ -10,6 +10,18 @@ CodeRef.prototype.block = function(func) {
func.codeRef = this;
};

// HACK - do this properly
CodeRef.prototype.$call = function() {
var nqp = require('nqp-runtime');
if (this["$!do"].closureTemplate) {
console.log(this["$!do"]);
var template = "var " + this["$!do"].outerCtx + "= null;(" + this["$!do"].closureTemplate + ")";
this.$call = eval(template);
this.$call.codeRef = this;
return this.$call.apply(this, arguments);
}
}

CodeRef.prototype.$apply = function _(argsArray) {
return this.$call.apply(this, argsArray);
};
Expand All @@ -25,10 +37,8 @@ CodeRef.prototype.capture = function(block) {
};

CodeRef.prototype.closure = function(block) {
this.$call = block; // HACK - we need to figure what needs to replace this

var closure = new CodeRef(this.name, undefined);
closure.codeObj = this.codeObj; // HACK it seems that MoarVM doesn't do it
closure.codeObj = this.codeObj;
closure.$call = block;
closure.$call.codeRef = closure;
return closure;
Expand Down

0 comments on commit 0d93c7c

Please sign in to comment.