-
Notifications
You must be signed in to change notification settings - Fork 361
Open
Description
I'm trying to adopt JS-INterpreter, to a library that I've creted earlier, JS-Interpreter does contain two helper functions createnativefunction and createasync function, but none of them worked for my functions so here is my take.
/**
* Create a new native function.
* @param {!Function} nativeFunc JavaScript function.
* @param {boolean} isConstructor True if function can be used with 'new'.
* @returns {!Interpreter.Object} New function.
*/
Interpreter.prototype.wrap_direct_function = function(nativeFunc,
isConstructor) {
var func = this.createFunctionBase_(nativeFunc.length, isConstructor);
func.direct_func = nativeFunc;
nativeFunc.id = this.functionCounter_++;
this.setProperty(func, 'name', nativeFunc.name,
Interpreter.READONLY_NONENUMERABLE_DESCRIPTOR);
return func;
};
//and this
} else if (func.direct_func) {
if (!state.scope.strict) {
state.funcThis_ = this.boxThis_(state.funcThis_);
}
var thisInterpreter = this;
this.paused_ = true;
var args=[... state.arguments_,function(err,result){
state.value=result;
thisInterpreter.paused_ = false;
}];
func.direct_func.apply(state.funcThis_,args);
return;
The diffrance is that I am not cheking argument length, and that I accept a standard nodeback instead of a single parameter callback.
I am bumping into
if (!(func instanceof Interpreter.Object)) {
this.throwException(this.TYPE_ERROR,
this.nodeSummary(node.callee) + ' is not a function');
}
This might be unrelated at all, but I wonder if you see any obvious reasons why my hacks couldn't work.
Metadata
Metadata
Assignees
Labels
No labels