public static <T> T getTypedProperty(Scriptable s, String name, Class<T> type) { return ScriptableObject.getTypedProperty(s, name, type); }
public static <T> T getTypedProperty(Scriptable s, int index, Class<T> type) { return ScriptableObject.getTypedProperty(s, index, type); }
@Override public Object exec(Context cx, Scriptable scope) { String id = ScriptableObject.getTypedProperty(ScriptableObject.getTypedProperty( scope, "module", Scriptable.class), "id", String.class); if ( partialOldExports.containsKey(id) ) { synchronized (partialOldExports) { partialOldExports.remove(id); } partialExecutionScopes.remove(id); } return Undefined.instance; } }
private void makeEventful(Scriptable stream) { Function require = ScriptableObject.getTypedProperty(scope, "require", Function.class); Scriptable events = (Scriptable) require.call(context, scope, scope, new Object[]{"events"}); Scriptable utils = (Scriptable) require.call(context, scope, scope, new Object[]{"util"}); Function inherits = ScriptableObject.getTypedProperty(utils, "inherits", Function.class); Function eventEmitter = ScriptableObject.getTypedProperty(events, "EventEmitter", Function.class); inherits.call(context,scope,scope,new Object[]{stream, eventEmitter}); }
String fullPath = getModulePath(scope); String id = ScriptableObject.getTypedProperty(ScriptableObject.getTypedProperty( scope, "module", Scriptable.class), "id", String.class); Scriptable newExport = ScriptableObject.getTypedProperty( partialExecutionScopes.get(stringScriptableEntry.getKey()), "exports", Scriptable.class); Scriptable newModuleExport = ScriptableObject.getTypedProperty(ScriptableObject.getTypedProperty( partialExecutionScopes.get(stringScriptableEntry.getKey()), "module", Scriptable.class), "exports", Scriptable.class); partialOldExports.put(id, ScriptableObject.getTypedProperty(scope, "exports", Scriptable.class)); partialExecutionScopes.put(id, scope);
@Override public Object call(Context cx, Scriptable scope, final Scriptable originalThisObj, Object[] args) { final Function emit = ScriptableObject.getTypedProperty(originalThisObj, "emit", Function.class);
public TryExtensionsResult tryExtensions(String id, ModuleScope thisObj) { File cwdFile = getBasePathForModule(thisObj); NativeObject extensions = ScriptableObject.getTypedProperty(this, "extensions", NativeObject.class); Object[] propertyIds = ScriptableObject.getPropertyIds(extensions); if (!(id.startsWith("./") || id.startsWith("../") || id.startsWith("/"))) { return null; } for (Object extension : propertyIds) { String extensionAsString = (String) extension; File file; if ( cwdFile != null ) { file = new File(FilenameUtils.concat(cwdFile.getAbsolutePath(), id + extensionAsString)); /* Case of ./ only where we need to add index.js */ if (!file.exists()) { file = new File(FilenameUtils.concat(cwdFile.getAbsolutePath(), id + "index" + extensionAsString)); } } else { /* Case of /a/b/c.js */ file = new File(id + extensionAsString); } if ( file.exists() ) { Function value = ScriptableObject.getTypedProperty(extensions, extensionAsString, Function.class); return new TryExtensionsResult(extensionAsString, value, file); } } return null; }
private ModuleSource loadFromPathArray(String moduleId, Scriptable paths, Object validator) throws IOException { final long llength = ScriptRuntime.toUint32( ScriptableObject.getProperty(paths, "length")); // Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me. int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)llength; for(int i = 0; i < ilength; ++i) { final String path = ensureTrailingSlash( ScriptableObject.getTypedProperty(paths, i, String.class)); try { URI uri = new URI(path); if (!uri.isAbsolute()) { uri = new File(path).toURI().resolve(""); } final ModuleSource moduleSource = loadFromUri( uri.resolve(moduleId), uri, validator); if(moduleSource != null) { return moduleSource; } } catch(URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } } return null; }
private ModuleSource loadFromPathArray(String moduleId, Scriptable paths, Object validator) throws IOException { final long llength = ScriptRuntime.toUint32( ScriptableObject.getProperty(paths, "length")); // Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me. int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)llength; for(int i = 0; i < ilength; ++i) { final String path = ensureTrailingSlash( ScriptableObject.getTypedProperty(paths, i, String.class)); try { URI uri = new URI(path); if (!uri.isAbsolute()) { uri = new File(path).toURI().resolve(""); } final ModuleSource moduleSource = loadFromUri( uri.resolve(moduleId), uri, validator); if(moduleSource != null) { return moduleSource; } } catch(URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } } return null; }
private ModuleSource loadFromPathArray(String moduleId, Scriptable paths, Object validator) throws IOException { final long llength = ScriptRuntime.toUint32( ScriptableObject.getProperty(paths, "length")); // Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me. int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)llength; for(int i = 0; i < ilength; ++i) { final String path = ensureTrailingSlash( ScriptableObject.getTypedProperty(paths, i, String.class)); try { URI uri = new URI(path); if (!uri.isAbsolute()) { uri = new File(path).toURI().resolve(""); } final ModuleSource moduleSource = loadFromUri( uri.resolve(moduleId), uri, validator); if(moduleSource != null) { return moduleSource; } } catch(URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } } return null; }
private ModuleSource loadFromPathArray(String moduleId, Scriptable paths, Object validator) throws IOException { final long llength = ScriptRuntime.toUint32( ScriptableObject.getProperty(paths, "length")); // Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me. int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)llength; for(int i = 0; i < ilength; ++i) { final String path = ensureTrailingSlash( ScriptableObject.getTypedProperty(paths, i, String.class)); try { URI uri = new URI(path); if (!uri.isAbsolute()) { uri = new File(path).toURI().resolve(""); } final ModuleSource moduleSource = loadFromUri( uri.resolve(moduleId), uri, validator); if(moduleSource != null) { return moduleSource; } } catch(URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } } return null; }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { Scriptable repl = (Scriptable) ScriptableObject.getTypedProperty(scope, "require", Function.class) .call(cx, scope, thisObj, new Object[]{"repl"}); Function start = ScriptableObject.getTypedProperty(repl, "start", Function.class); Scriptable options = cx.newObject(scope); ScriptableObject.putProperty(options, "prompt", Context.javaToJS(PROMPT, scope)); ScriptableObject.putProperty(options, "terminal", Context.javaToJS(true, scope)); start.call(cx, scope, thisObj, new Object[]{options}); return Undefined.instance; } });
Scriptable extensions = ScriptableObject.getTypedProperty(this, "extensions", Scriptable.class); } else if ( file.exists() && !file.isDirectory() && ScriptableObject.hasProperty(extensions, "." + FilenameUtils.getExtension(id) ) ) { return ScriptableObject.getTypedProperty(extensions, "." + FilenameUtils.getExtension( id), Function.class ).call(cx, scope, thisObj, new Object[]{thisObj, id});