Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Intentional errors from an executed script #29

Open
seubert opened this issue May 27, 2014 · 1 comment
Open

Intentional errors from an executed script #29

seubert opened this issue May 27, 2014 · 1 comment

Comments

@seubert
Copy link

seubert commented May 27, 2014

Right now the only way to return from a script is via the exit() function in sandbox.js. I am looking to add a way to intentionally return errors so they can be more efficiently reported as such. Would there be any interest in this from others or ideas on the best way to implement it?

@dashed
Copy link

dashed commented Jun 7, 2014

I'm interested in this as well.

As per my comments at #28 (comment). One could get the returned value from the closure (and thus from the script) and feed it into the exit function.

The following would do this:

Sandbox.prototype.wrapForExecution = function(source) {
  return "\"use strict\";\
  var sandbox = Object.create(null);\
  sandbox.exit = exit;\
  Object.freeze(sandbox);\
  var exports = Object.create(null);\
  var exit_val = (function() {\
  var sandbox = null;\
  " + source + "})();\
  typeof exports." + methodName + " === \"function\" && exports." + methodName + "();\
  sandbox.exit(exit_val);";
};

@bcoe Thoughts on this?

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

No branches or pull requests

2 participants