@Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!f.hasTag(CLASS_NAME)) { return super.execIdCall(f, cx, scope, thisObj, args); } int id = f.methodId(); switch (id) { case ConstructorId_isView: return (isArg(args, 0) && (args[0] instanceof NativeArrayBufferView)); case Id_constructor: int length = isArg(args, 0) ? ScriptRuntime.toInt32(args[0]) : 0; return new NativeArrayBuffer(length); case Id_slice: NativeArrayBuffer self = realThis(thisObj, f); int start = isArg(args, 0) ? ScriptRuntime.toInt32(args[0]) : 0; int end = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : self.buffer.length; return self.slice(start, end); } throw new IllegalArgumentException(String.valueOf(id)); }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeInt16Array)) { throw incompatibleCallError(f); } return (NativeInt16Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeUint8Array)) { throw incompatibleCallError(f); } return (NativeUint8Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeFloat64Array)) { throw incompatibleCallError(f); } return (NativeFloat64Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeUint32Array)) { throw incompatibleCallError(f); } return (NativeUint32Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeUint16Array)) { throw incompatibleCallError(f); } return (NativeUint16Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeUint8ClampedArray)) { throw incompatibleCallError(f); } return (NativeUint8ClampedArray)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeInt32Array)) { throw incompatibleCallError(f); } return (NativeInt32Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeInt8Array)) { throw incompatibleCallError(f); } return (NativeInt8Array)thisObj; }
@Override protected NativeTypedArrayView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeFloat32Array)) { throw incompatibleCallError(f); } return (NativeFloat32Array)thisObj; }
@Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!f.hasTag(REGEXP_TAG)) { return super.execIdCall(f, cx, scope, thisObj, args); } int id = f.methodId(); switch (id) { case Id_compile: return realThis(thisObj, f).compile(cx, scope, args); case Id_toString: case Id_toSource: return realThis(thisObj, f).toString(); case Id_exec: return realThis(thisObj, f).execSub(cx, scope, args, MATCH); case Id_test: { Object x = realThis(thisObj, f).execSub(cx, scope, args, TEST); return Boolean.TRUE.equals(x) ? Boolean.TRUE : Boolean.FALSE; } case Id_prefix: return realThis(thisObj, f).execSub(cx, scope, args, PREFIX); } throw new IllegalArgumentException(String.valueOf(id)); }
/** * {@inheritDoc} */ @Override public void contributeToScope(final Object scope, final boolean trustworthyScript, final boolean mutableScope) { if (scope instanceof Scriptable) { final IdFunctionObject func = new IdFunctionObject(this, EXECUTE_BATCH_FUNC_TAG, EXECUTE_BATCH_FUNC_ID, EXECUTE_BATCH_FUNC_NAME, ARITY, (Scriptable) scope); func.sealObject(); // export as read-only and undeleteable property of the scope ScriptableObject.defineProperty((Scriptable) scope, EXECUTE_BATCH_FUNC_NAME, func, ScriptableObject.PERMANENT | ScriptableObject.READONLY); } }
protected void exportFunction(final int methodId, final String name, final int arity, final Scriptable scope) { final IdFunctionObject func = new IdFunctionObject(this, LOG_FUNC_TAG, methodId, name, arity, scope); func.sealObject(); // export as read-only and undeleteable property of the scope ScriptableObject.defineProperty(scope, name, func, ScriptableObject.PERMANENT | ScriptableObject.READONLY); }
/** * {@inheritDoc} */ @Override public void contributeToScope(final Object scope, final boolean trustworthyScript, final boolean mutableScope) { if (scope instanceof Scriptable) { final IdFunctionObject func = new IdFunctionObject(this, IMPORT_FUNC_TAG, IMPORT_FUNC_ID, IMPORT_FUNC_NAME, ARITY, (Scriptable) scope); func.sealObject(); // export as read-only and undeleteable property of the scope ScriptableObject.defineProperty((Scriptable) scope, IMPORT_FUNC_NAME, func, ScriptableObject.PERMANENT | ScriptableObject.READONLY); } }
private static NativeArrayBuffer realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeArrayBuffer)) throw incompatibleCallError(f); return (NativeArrayBuffer)thisObj; }
@Override protected void fillConstructorProperties(IdFunctionObject ctor) { addIdFunctionProperty(ctor, CLASS_NAME, ConstructorId_isView, "isView", 1); }
@Override protected void fillConstructorProperties(IdFunctionObject ctor) { ctor.put("BYTES_PER_ELEMENT", ctor, ScriptRuntime.wrapInt(getBytesPerElement())); }
private static NativeDataView realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeDataView)) throw incompatibleCallError(f); return (NativeDataView)thisObj; }
@Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!f.hasTag(getClassName())) { return super.execIdCall(f, cx, scope, thisObj, args); } int id = f.methodId(); switch (id) { case Id_constructor: if (isArg(args, 0) && (args[0] instanceof NativeArrayBuffer)) { NativeArrayBuffer ab = (NativeArrayBuffer)args[0]; int off = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0; int len = isArg(args, 2) ? ScriptRuntime.toInt32(args[2]) : ab.getLength() - off; return js_constructor(ab, off, len); } else { throw ScriptRuntime.constructError("TypeError", "Missing parameters"); } case Id_getInt8: return realThis(thisObj, f).js_getInt(1, true, args); case Id_getUint8: return realThis(thisObj, f).js_getInt(1, false, args); case Id_getInt16: return realThis(thisObj, f).js_getInt(2, true, args); case Id_getUint16: return realThis(thisObj, f).js_getInt(2, false, args); case Id_getInt32: return realThis(thisObj, f).js_getInt(4, true, args); case Id_getUint32: return realThis(thisObj, f).js_getInt(4, false, args); case Id_getFloat32: return realThis(thisObj, f).js_getFloat(4, args); case Id_getFloat64: return realThis(thisObj, f).js_getFloat(8, args); case Id_setInt8: realThis(thisObj, f).js_setInt(1, true, args); return Undefined.instance; case Id_setUint8: realThis(thisObj, f).js_setInt(1, false, args); return Undefined.instance; case Id_setInt16: realThis(thisObj, f).js_setInt(2, true, args); return Undefined.instance; case Id_setUint16: realThis(thisObj, f).js_setInt(2, false, args); return Undefined.instance; case Id_setInt32: realThis(thisObj, f).js_setInt(4, true, args); return Undefined.instance; case Id_setUint32: realThis(thisObj, f).js_setInt(4, false, args); return Undefined.instance; case Id_setFloat32: realThis(thisObj, f).js_setFloat(4, args); return Undefined.instance; case Id_setFloat64: realThis(thisObj, f).js_setFloat(8, args); return Undefined.instance; } throw new IllegalArgumentException(String.valueOf(id)); }
private static NativeRegExp realThis(Scriptable thisObj, IdFunctionObject f) { if (!(thisObj instanceof NativeRegExp)) throw incompatibleCallError(f); return (NativeRegExp)thisObj; }