Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to ease calling outside functions from the sandbox #278

Open
neimanpinchas opened this issue Sep 29, 2024 · 0 comments
Open

Trying to ease calling outside functions from the sandbox #278

neimanpinchas opened this issue Sep 29, 2024 · 0 comments

Comments

@neimanpinchas
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant