/** * Gets the window that is the top scope for the specified object. * @param s the JavaScript object whose associated window is to be returned * @return the window associated with the specified JavaScript object * @throws RuntimeException if the window cannot be found, which should never occur */ protected static Window getWindow(final Scriptable s) throws RuntimeException { final Scriptable top = ScriptableObject.getTopLevelScope(s); if (top instanceof Window) { return (Window) top; } throw new RuntimeException("Unable to find window associated with " + s); }
/** * Gets the window that is the top scope for the specified object. * @param s the JavaScript object whose associated window is to be returned * @return the window associated with the specified JavaScript object * @throws RuntimeException if the window cannot be found, which should never occur */ protected static Window getWindow(final Scriptable s) throws RuntimeException { final Scriptable top = ScriptableObject.getTopLevelScope(s); if (top instanceof Window) { return (Window) top; } throw new RuntimeException("Unable to find window associated with " + s); }
/** * Gets the window that is the top scope for the specified object. * @param s the JavaScript object whose associated window is to be returned * @return the window associated with the specified JavaScript object * @throws RuntimeException if the window cannot be found, which should never occur */ protected static Window getWindow(final Scriptable s) throws RuntimeException { final Scriptable top = ScriptableObject.getTopLevelScope(s); if (top instanceof Window) { return (Window) top; } throw new RuntimeException("Unable to find window associated with " + s); }
/** * Gets the window that is the top scope for the specified object. * @param s the JavaScript object whose associated window is to be returned * @return the window associated with the specified JavaScript object * @throws RuntimeException if the window cannot be found, which should never occur */ protected static Window getWindow(final Scriptable s) throws RuntimeException { final Scriptable top = ScriptableObject.getTopLevelScope(s); if (top instanceof Window) { return (Window) top; } throw new RuntimeException("Unable to find window associated with " + s); }
/** * Get the value of the "StopIteration" object. Note that this value * is stored in the top-level scope using "associateValue" so the * value can still be found even if a script overwrites or deletes * the global "StopIteration" property. * @param scope a scope whose parent chain reaches a top-level scope * @return the StopIteration object */ public static Object getStopIterationObject(Scriptable scope) { Scriptable top = ScriptableObject.getTopLevelScope(scope); return ScriptableObject.getTopScopeValue(top, ITERATOR_TAG); }
public static Object getTopLevelProp(Scriptable scope, String id) { scope = ScriptableObject.getTopLevelScope(scope); return ScriptableObject.getProperty(scope, id); }
public Object run(Context cx) { Scriptable scope = ScriptableObject.getTopLevelScope(generator); Callable closeGenerator = new Callable() { public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { return ((NativeGenerator)thisObj).resume(cx, scope, GENERATOR_CLOSE, new GeneratorClosedException()); } }; return ScriptRuntime.doTopCall(closeGenerator, cx, scope, generator, null); } }
public final void initPrototypeMethod(Object tag, int id, String name, int arity) { Scriptable scope = ScriptableObject.getTopLevelScope(this); IdFunctionObject f = newIdFunction(tag, id, name, arity, scope); prototypeValues.initValue(id, name, f, DONTENUM); }
public static Scriptable newObject(Context cx, Scriptable scope, String constructorName, Object[] args) { scope = ScriptableObject.getTopLevelScope(scope); Function ctor = getExistingCtor(cx, scope, constructorName); if (args == null) { args = ScriptRuntime.emptyArgs; } return ctor.construct(cx, scope, args); }
public static Scriptable createAdapterWrapper(Scriptable obj, Object adapter) { Scriptable scope = ScriptableObject.getTopLevelScope(obj); NativeJavaObject res = new NativeJavaObject(scope, adapter, null, true); res.setPrototype(obj); return res; }
protected void addIdFunctionProperty(Scriptable obj, Object tag, int id, String name, int arity) { Scriptable scope = ScriptableObject.getTopLevelScope(obj); IdFunctionObject f = newIdFunction(tag, id, name, arity, scope); f.addAsProperty(obj); }
/** * {@inheritDoc} * @see ScriptableObject#get(int, net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final int index, final Scriptable start) { if (getByIndexMethod_ != null) { final Object byIndex = invoke(getByIndexMethod_, new Object[] {Integer.valueOf(index)}); return Context.javaToJS(byIndex, ScriptableObject.getTopLevelScope(start)); } return super.get(index, start); }
/** * {@inheritDoc} * @see ScriptableObject#get(int, net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final int index, final Scriptable start) { if (getByIndexMethod_ != null) { final Object byIndex = invoke(getByIndexMethod_, new Object[] {Integer.valueOf(index)}); return Context.javaToJS(byIndex, ScriptableObject.getTopLevelScope(start)); } return super.get(index, start); }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { Scriptable s = ScriptableObject.getTopLevelScope(scope); mdata.arrayobj = ScriptRuntime.newObject(cx, s, "Array", null); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
/** * Returns the value of the {@code frames} property. * @see <a href="http://msdn.microsoft.com/en-us/library/ms537459.aspx">MSDN documentation</a> * @return the live collection of frames contained by this document */ @JsxGetter(IE) public Object getFrames() { if (ScriptableObject.getTopLevelScope(this) == null) { throw ScriptRuntime.constructError("Error", "Not implemented"); } return getWindow().getFrames_js(); }
public static void setObjectProtoAndParent(ScriptableObject object, Scriptable scope) { // Compared with function it always sets the scope to top scope scope = ScriptableObject.getTopLevelScope(scope); object.setParentScope(scope); Scriptable proto = ScriptableObject.getClassPrototype(scope, object.getClassName()); object.setPrototype(proto); }
/** * Returns the value of the {@code frames} property. * @see <a href="http://msdn.microsoft.com/en-us/library/ms537459.aspx">MSDN documentation</a> * @return the live collection of frames contained by this document */ @JsxGetter(IE) public Object getFrames() { if (ScriptableObject.getTopLevelScope(this) == null) { throw ScriptRuntime.constructError("Error", "Not implemented"); } return getWindow().getFrames_js(); }
static Object newWithSpecial(Context cx, Scriptable scope, Object[] args) { ScriptRuntime.checkDeprecated(cx, "With"); scope = ScriptableObject.getTopLevelScope(scope); NativeWith thisObj = new NativeWith(); thisObj.setPrototype(args.length == 0 ? ScriptableObject.getClassPrototype(scope, "Object") : ScriptRuntime.toObject(cx, scope, args[0])); thisObj.setParentScope(scope); return thisObj; }
/** * Initialize the parent scope of a newly created scriptable. * @param domNode the DOM node for the script object * @param scriptable the script object to initialize */ protected void initParentScope(final DomNode domNode, final SimpleScriptable scriptable) { final WebWindow enclosingWindow = domNode.getPage().getEnclosingWindow(); if (enclosingWindow.getEnclosedPage() == domNode.getPage()) { scriptable.setParentScope((Scriptable) enclosingWindow.getScriptObject()); } else { scriptable.setParentScope(ScriptableObject.getTopLevelScope(domNode.getPage().getScriptObject())); } }
/** * Initialize the parent scope of a newly created scriptable. * @param domNode the DOM node for the script object * @param scriptable the script object to initialize */ protected void initParentScope(final DomNode domNode, final SimpleScriptable scriptable) { final WebWindow enclosingWindow = domNode.getPage().getEnclosingWindow(); if (enclosingWindow.getEnclosedPage() == domNode.getPage()) { scriptable.setParentScope((Scriptable) enclosingWindow.getScriptObject()); } else { scriptable.setParentScope(ScriptableObject.getTopLevelScope(domNode.getPage().getScriptObject())); } }