@Override public ScriptObjectMirror newJsObject() { return (ScriptObjectMirror) this.objectProto.newObject(); }
@Override public ScriptObjectMirror newJsArray() { return (ScriptObjectMirror) this.arrayProto.newObject(); }
private Bindings createSafeBindings() throws ScriptException { // As explained in https://github.com/coveo/nashorn-commonjs-modules/pull/16/files a plain // SimpleBindings has quite a few limitations in Nashorn compared to a ScriptObject, so // whenever we need an instance of those (for `exports` etc.) we create a real JS object. return (ScriptObjectMirror) objectConstructor.newObject(); }
private Bindings createSafeBindings() throws ScriptException { // As explained in https://github.com/coveo/nashorn-commonjs-modules/pull/16/files a plain // SimpleBindings has quite a few limitations in Nashorn compared to a ScriptObject, so // whenever we need an instance of those (for `exports` etc.) we create a real JS object. return (ScriptObjectMirror) objectConstructor.newObject(); }
private void throwModuleNotFoundException(String module) throws ScriptException { Bindings error = (Bindings) errorConstructor.newObject("Module not found: " + module); error.put("code", "MODULE_NOT_FOUND"); throw new ECMAException(error, null); }
private void throwModuleNotFoundException(String module) throws ScriptException { Bindings error = (Bindings) errorConstructor.newObject("Module not found: " + module); error.put("code", "MODULE_NOT_FOUND"); throw new ECMAException(error, null); }
@Override public void stop(Future<Void> stopFuture) throws Exception { if (functionExists(VERTX_STOP_FUNCTION)) { exports.callMember(VERTX_STOP_FUNCTION); stopFuture.complete(); } else if (functionExists(VERTX_STOP_ASYNC_FUNCTION)) { Object wrappedFuture = futureJSClass.newObject(stopFuture); exports.callMember(VERTX_STOP_ASYNC_FUNCTION, wrappedFuture); } else { stopFuture.complete(); } } }
@Override public void start(Future<Void> startFuture) throws Exception { /* NOTE: When we deploy a verticle we use require.noCache as each verticle instance must have the module evaluated. Also we run verticles in JS strict mode (with "use strict") -this means they cannot declare globals and other restrictions. We do this for isolation. However when doing a normal 'require' from inside a verticle we do not use strict mode as many JavaScript modules are written poorly and would fail to run otherwise. */ exports = (ScriptObjectMirror) engine.eval("require.noCache('" + verticleName + "', null, true);"); if (functionExists(VERTX_START_FUNCTION)) { exports.callMember(VERTX_START_FUNCTION); startFuture.complete(); } else if (functionExists(VERTX_START_ASYNC_FUNCTION)) { Object wrappedFuture = futureJSClass.newObject(startFuture); exports.callMember(VERTX_START_ASYNC_FUNCTION, wrappedFuture); } else { startFuture.complete(); } }