/** * {@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 void putProperty(String name, Object value) { ScriptableObject.putProperty(global, name, value); }
private static Object getRawElem(Scriptable target, long index) { if (index > Integer.MAX_VALUE) { return ScriptableObject.getProperty(target, Long.toString(index)); } else { return ScriptableObject.getProperty(target, (int) index); } }
/** * 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); }
/** * Removes prototype properties. * @param window the scope * @param className the class for which properties should be removed * @param properties the properties to remove */ private void removePrototypeProperties(final Window window, final String className, final String[] properties) { final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, className); for (final String property : properties) { prototype.delete(property); } }
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); }
final FunctionObject functionObject = new RecursiveFunctionObject("Window", windowConfig.getJsConstructor(), window); ScriptableObject.defineProperty(window, "constructor", functionObject, ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); final ScriptableObject errorObject = (ScriptableObject) ScriptableObject.getProperty(window, "Error"); if (browserVersion.hasFeature(JS_ERROR_STACK_TRACE_LIMIT)) { errorObject.defineProperty("stackTraceLimit", 10, ScriptableObject.EMPTY); ScriptableObject.deleteProperty(errorObject, "stackTraceLimit"); ScriptableObject.deleteProperty(errorObject, "captureStackTrace"); obj.setParentScope(window); obj.setClassName(config.getClassName()); ScriptableObject.defineProperty(window, obj.getClassName(), obj, ScriptableObject.DONTENUM); final ScriptableObject constructor; if ("Window".equals(jsClassName)) { constructor = (ScriptableObject) ScriptableObject.getProperty(window, "constructor"); final BaseFunction function; if ("Window".equals(jsClassName)) { function = (BaseFunction) ScriptableObject.getProperty(window, "constructor"); || "Image".equals(hostClassSimpleName) || "Option".equals(hostClassSimpleName)) { final Object prototypeProperty = ScriptableObject.getProperty(window, prototype.getClassName());
/** * Install the wrapper in place of the native toString function on Function's prototype. * @param window the scope * @param browserVersion the simulated browser */ static void installFix(final Scriptable window, final BrowserVersion browserVersion) { if (browserVersion.hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE)) { final ScriptableObject fnPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "Function"); final Function originalToString = (Function) ScriptableObject.getProperty(fnPrototype, "toString"); final Function newToString = new NativeFunctionToStringFunction(originalToString); ScriptableObject.putProperty(fnPrototype, "toString", newToString); } else if (browserVersion.hasFeature(JS_NATIVE_FUNCTION_TOSTRING_COMPACT)) { final ScriptableObject fnPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "Function"); final Function originalToString = (Function) ScriptableObject.getProperty(fnPrototype, "toString"); final Function newToString = new NativeFunctionToStringFunctionChrome(originalToString); ScriptableObject.putProperty(fnPrototype, "toString", newToString); } else if (browserVersion.hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NL)) { final ScriptableObject fnPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "Function"); final Function originalToString = (Function) ScriptableObject.getProperty(fnPrototype, "toString"); final Function newToString = new NativeFunctionToStringFunctionFF(originalToString); ScriptableObject.putProperty(fnPrototype, "toString", newToString); } }
private static String getAttributeValue(final DomElement element, final String attribute) { // first try real attributes String value = element.getAttribute(attribute); if (DomElement.ATTRIBUTE_NOT_DEFINED == value && !(element instanceof HtmlApplet) && !(element instanceof HtmlObject)) { // second try are JavaScript attributes // ...but applets/objects are a bit special so ignore them final Object o = element.getScriptableObject(); if (o instanceof ScriptableObject) { final ScriptableObject scriptObject = (ScriptableObject) o; // we have to make sure the scriptObject has a slot for the given attribute. // just using get() may use e.g. getWithPreemption(). if (scriptObject.has(attribute, scriptObject)) { final Object jsValue = scriptObject.get(attribute, scriptObject); if (jsValue != Scriptable.NOT_FOUND && jsValue instanceof String) { value = (String) jsValue; } } } } return value; }
/** * <p>If IE is emulated, and this class does not have the specified property, and the owning * select *does* have the specified property, this method delegates the call to the parent * select element.</p> * * @param name {@inheritDoc} * @param start {@inheritDoc} * @param value {@inheritDoc} */ @Override public void put(final String name, final Scriptable start, final Object value) { if (htmlSelect_ == null) { // This object hasn't been initialized; it's probably being used as a prototype. // Just pretend we didn't even see this invocation and let Rhino handle it. super.put(name, start, value); return; } final HTMLSelectElement parent = htmlSelect_.getScriptableObject(); if (!has(name, start) && ScriptableObject.hasProperty(parent, name)) { ScriptableObject.putProperty(parent, name, value); } else { super.put(name, start, value); } }
protected final void defaultPut(String name, Object value) { super.put(name, this, value); }
protected final Object defaultGet(String name) { return super.get(name, this); }
protected boolean isAccessorDescriptor(ScriptableObject desc) { return hasProperty(desc, "get") || hasProperty(desc, "set"); }
public static Object getTopLevelProp(Scriptable scope, String id) { scope = ScriptableObject.getTopLevelScope(scope); return ScriptableObject.getProperty(scope, id); }
NativeJavaPackage forcePackage(String name, Scriptable scope) { Object cached = super.get(name, this); if (cached != null && cached instanceof NativeJavaPackage) { return (NativeJavaPackage) cached; } else { String newPackage = packageName.length() == 0 ? name : packageName + "." + name; NativeJavaPackage pkg = new NativeJavaPackage(true, newPackage, classLoader); ScriptRuntime.setObjectProtoAndParent(pkg, scope); super.put(name, this, pkg); return pkg; } }
if (doc instanceof XmlPage) { final ScriptableObject scriptable = ((XmlPage) doc).getScriptableObject(); if (ScriptableObject.hasProperty(scriptable, "getProperty")) { final Object selectionNS = ScriptableObject.callMethod(scriptable, "getProperty", new Object[]{"SelectionNamespaces"}); if (selectionNS != null && !selectionNS.toString().isEmpty()) { final Map<String, String> namespaces = parseSelectionNamespaces(selectionNS.toString());
private void defineMethod(final String methodName, final Scriptable scope) { for (Method method : getClass().getMethods()) { if (method.getName().equals(methodName)) { final FunctionObject functionObject = new FunctionObject(methodName, method, scope); ((ScriptableObject) scope).defineProperty(methodName, functionObject, ScriptableObject.EMPTY); } } }
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; }