/** * Get the Function.prototype property. * See ECMA 15.3.4. */ public static Scriptable getFunctionPrototype(Scriptable scope) { return getClassPrototype(scope, "Function"); }
public Scriptable getPrototype() { if (prototype == null && javaObject instanceof String) { return ScriptableObject.getClassPrototype(parent, "String"); } return prototype; }
/** * Get the Object.prototype property. * See ECMA 15.2.4. */ public static Scriptable getObjectPrototype(Scriptable scope) { return getClassPrototype(scope, "Object"); }
@Override public Scriptable getPrototype() { if (prototype == null) { prototype = ScriptableObject.getClassPrototype(this.getParentScope(), "Array"); } return prototype; }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * Removes prototype properties. * @param scope the scope * @param className the class for which properties should be removed * @param properties the properties to remove */ private static void removePrototypeProperties(final Scriptable scope, final String className, final String... properties) { final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(scope, className); for (final String property : properties) { prototype.delete(property); } }
/** * Removes prototype properties. * @param scope the scope * @param className the class for which properties should be removed * @param properties the properties to remove */ private static void removePrototypeProperties(final Scriptable scope, final String className, final String... properties) { final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(scope, 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); }
/** * Reads the contents of the specified {@link Blob} or {@link File}. * @param object the {@link Blob} or {@link File} from which to read * @throws IOException if an error occurs */ @JsxFunction public void readAsArrayBuffer(final Object object) throws IOException { readyState_ = LOADING; final java.io.File file = ((File) object).getFile(); try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { FileUtils.copyFile(file, bos); final byte[] bytes = bos.toByteArray(); final NativeArrayBuffer buffer = new NativeArrayBuffer(bytes.length); System.arraycopy(bytes, 0, buffer.getBuffer(), 0, bytes.length); buffer.setParentScope(getParentScope()); buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); result_ = buffer; } readyState_ = DONE; final Event event = new Event(this, Event.TYPE_LOAD); fireEvent(event); }
/** * Reads the contents of the specified {@link Blob} or {@link File}. * @param object the {@link Blob} or {@link File} from which to read * @throws IOException if an error occurs */ @JsxFunction public void readAsArrayBuffer(final Object object) throws IOException { readyState_ = LOADING; final java.io.File file = ((File) object).getFile(); try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { FileUtils.copyFile(file, bos); final byte[] bytes = bos.toByteArray(); final NativeArrayBuffer buffer = new NativeArrayBuffer(bytes.length); System.arraycopy(bytes, 0, buffer.getBuffer(), 0, bytes.length); buffer.setParentScope(getParentScope()); buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); result_ = buffer; } readyState_ = DONE; final Event event = new Event(this, Event.TYPE_LOAD); fireEvent(event); }
/** * 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); } }
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; }
final NativeUint8Array result = new NativeUint8Array(0); result.setParentScope(getParentScope()); result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); return result; result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); return result;
/** * Returns a {@link NativeUint8ClampedArray} representing a one-dimensional array containing * the data in the RGBA order, with integer values between 0 and 255 (included). * @return the {@code data} property */ @JsxGetter public NativeUint8ClampedArray getData() { if (data_ == null) { final byte[] bytes = renderingContext_.getBytes(width_, height_, sx_, sy_); final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length); System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length); data_ = new NativeUint8ClampedArray(arrayBuffer, 0, bytes.length); data_.setParentScope(getParentScope()); data_.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), data_.getClassName())); } return data_; }
final NativeUint8Array result = new NativeUint8Array(0); result.setParentScope(getParentScope()); result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); return result; result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); return result;
/** * Returns a {@link NativeUint8ClampedArray} representing a one-dimensional array containing * the data in the RGBA order, with integer values between 0 and 255 (included). * @return the {@code data} property */ @JsxGetter public NativeUint8ClampedArray getData() { if (data_ == null) { final byte[] bytes = renderingContext_.getBytes(width_, height_, sx_, sy_); final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length); System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length); data_ = new NativeUint8ClampedArray(arrayBuffer, 0, bytes.length); data_.setParentScope(getParentScope()); data_.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), data_.getClassName())); } return data_; }
@Override public void onWebSocketBinary(final byte[] data, final int offset, final int length) { if (listener_ != null) { listener_.onWebSocketBinary(data, offset, length); } super.onWebSocketBinary(data, offset, length); final NativeArrayBuffer buffer = new NativeArrayBuffer(length); System.arraycopy(data, offset, buffer.getBuffer(), 0, length); buffer.setParentScope(getParentScope()); buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); final MessageEvent msgEvent = new MessageEvent(buffer); msgEvent.setOrigin(getUrl()); fire(msgEvent); callFunction(messageHandler_, new Object[] {msgEvent}); }
@Override public void onWebSocketBinary(final byte[] data, final int offset, final int length) { if (listener_ != null) { listener_.onWebSocketBinary(data, offset, length); } super.onWebSocketBinary(data, offset, length); final NativeArrayBuffer buffer = new NativeArrayBuffer(length); System.arraycopy(data, offset, buffer.getBuffer(), 0, length); buffer.setParentScope(getParentScope()); buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); final MessageEvent msgEvent = new MessageEvent(buffer); msgEvent.setOrigin(getUrl()); fire(msgEvent); callFunction(messageHandler_, new Object[] {msgEvent}); }