private void setupDefaultPrototype() { NativeObject obj = new NativeObject(); final int attr = ScriptableObject.DONTENUM; obj.defineProperty("constructor", this, attr); // put the prototype property into the object now, then in the // wacky case of a user defining a function Object(), we don't // get an infinite loop trying to find the prototype. prototypeProperty = obj; Scriptable proto = getObjectPrototype(this); if (proto != obj) { // not the one we just made, it must remain grounded obj.setPrototype(proto); } }
addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_getPrototypeOf, "getPrototypeOf", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_keys, "keys", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_getOwnPropertyNames, "getOwnPropertyNames", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_getOwnPropertyDescriptor, "getOwnPropertyDescriptor", 2); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_defineProperty, "defineProperty", 3); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_isExtensible, "isExtensible", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_preventExtensions, "preventExtensions", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_defineProperties, "defineProperties", 2); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_create, "create", 2); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_isSealed, "isSealed", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_isFrozen, "isFrozen", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_seal, "seal", 1); addIdFunctionProperty(ctor, OBJECT_TAG, ConstructorId_freeze, "freeze", 1); super.fillConstructorProperties(ctor);
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
private static void appendNativeObject(final NativeObject obj, final StringBuilder sb, final int level) { if (level == 0) { // For whatever reason, when a native object is printed at the // root level Firefox puts brackets outside it. This is not the // case when a native object is printed as part of an array or // inside another object. sb.append("("); } sb.append("{"); if (level < 3) { final Object[] ids = obj.getIds(); if (ids != null && ids.length > 0) { boolean needsSeparator = false; for (Object key : ids) { if (needsSeparator) { sb.append(", "); } sb.append(key); sb.append(":"); appendValue(obj.get(key), sb, level + 1); needsSeparator = true; } } } sb.append("}"); if (level == 0) { sb.append(")"); } }
obj = last.getAssociatedValue(t); if (obj == null) Kit.codeBug(); break getObj; NativeObject catchScopeObject = new NativeObject(); catchScopeObject.defineProperty( exceptionName, obj, ScriptableObject.PERMANENT); catchScopeObject.defineProperty( "__exception__", Context.javaToJS(t, scope), ScriptableObject.PERMANENT|ScriptableObject.DONTENUM); catchScopeObject.associateValue(t, obj);
return new NativeObject(); Scriptable obj = ensureScriptable(arg); return obj.getPrototype(); Scriptable obj = ensureScriptable(arg); Object[] ids = obj.getIds(); for (int i = 0; i < ids.length; i++) { ScriptableObject obj = ensureScriptableObject(arg); Object[] ids = obj.getAllIds(); for (int i = 0; i < ids.length; i++) { ScriptableObject obj = ensureScriptableObject(arg); Object nameArg = args.length < 2 ? Undefined.instance : args[1]; String name = ScriptRuntime.toString(nameArg); ScriptableObject obj = ensureScriptableObject(arg); Object name = args.length < 2 ? Undefined.instance : args[1]; Object descArg = args.length < 3 ? Undefined.instance : args[2]; ScriptableObject desc = ensureScriptableObject(descArg); obj.defineOwnProperty(cx, name, desc); return obj; ScriptableObject obj = ensureScriptableObject(arg); return obj.isExtensible(); ScriptableObject obj = ensureScriptableObject(arg); obj.preventExtensions();
/** * Creates a new event instance. * * @param target the event target * @param type the event type * @param state the state object */ public PopStateEvent(final EventTarget target, final String type, final Object state) { super(target, type); if (state instanceof NativeObject && getBrowserVersion().hasFeature(JS_POP_STATE_EVENT_CLONE_STATE)) { final NativeObject old = (NativeObject) state; final NativeObject newState = new NativeObject(); Context.enter(); try { for (final Object o : ScriptableObject.getPropertyIds(old)) { final String property = Context.toString(o); newState.defineProperty(property, ScriptableObject.getProperty(old, property), ScriptableObject.EMPTY); } } finally { Context.exit(); } state_ = newState; } else { state_ = state; } }
/** * Creates new script object. * The default implementation of {@link #construct} uses the method to * to get the value for <tt>thisObj</tt> argument when invoking * {@link #call}. * The methos is allowed to return <tt>null</tt> to indicate that * {@link #call} will create a new object itself. In this case * {@link #construct} will set scope and prototype on the result * {@link #call} unless they are already set. */ public Scriptable createObject(Context cx, Scriptable scope) { Scriptable newInstance = new NativeObject(); newInstance.setPrototype(getClassPrototype()); newInstance.setParentScope(getParentScope()); return newInstance; }
scope = new NativeObject(); NativeObject.init(scope, sealed);
attaributes_ = Boolean.TRUE.equals(options.get("attributes")); attributeOldValue_ = Boolean.TRUE.equals(options.get("attributeOldValue")); childList_ = Boolean.TRUE.equals(options.get("childList")); characterData_ = Boolean.TRUE.equals(options.get("characterData")); characterDataOldValue_ = Boolean.TRUE.equals(options.get("characterDataOldValue")); subtree_ = Boolean.TRUE.equals(options.get("subtree")); attributeFilter_ = (NativeArray) options.get("attributeFilter");
private static String formatToString(final Object o) { if (o == null) { return "null"; } else if (o instanceof NativeFunction) { return ((NativeFunction) o).toString(); } else if (o instanceof BaseFunction) { return "function " + ((BaseFunction) o).getFunctionName() + "\n" + " [native code]\n" + "}"; } else if (o instanceof NativeArray) { // If an array is embedded inside another array, just return // "[object Object]" return "[object Object]"; } else if (o instanceof Delegator) { return "[object " + ((Delegator) o).getDelegee().getClassName() + "]"; } else if (o instanceof NativeObject) { return "[object " + ((NativeObject) o).getClassName() + "]"; } else if (o instanceof SimpleScriptable) { return "[object " + ((SimpleScriptable) o).getClassName() + "]"; } else { return o.toString(); } }
/** * Creates a new event instance. * * @param target the event target * @param type the event type * @param state the state object */ public PopStateEvent(final EventTarget target, final String type, final Object state) { super(target, type); if (state instanceof NativeObject && getBrowserVersion().hasFeature(JS_POP_STATE_EVENT_CLONE_STATE)) { final NativeObject old = (NativeObject) state; final NativeObject newState = new NativeObject(); Context.enter(); try { for (final Object o : ScriptableObject.getPropertyIds(old)) { final String property = Context.toString(o); newState.defineProperty(property, ScriptableObject.getProperty(old, property), ScriptableObject.EMPTY); } } finally { Context.exit(); } state_ = newState; } else { state_ = state; } }
ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { ScriptableObject desc = new NativeObject(); ScriptRuntime.setObjectProtoAndParent(desc, scope); if (value != null) desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", (attributes & READONLY) == 0, EMPTY); desc.defineProperty("enumerable", (attributes & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attributes & PERMANENT) == 0, EMPTY); return desc; }
private static void appendNativeObject(final NativeObject obj, final StringBuilder sb, final int level) { if (level == 0) { // For whatever reason, when a native object is printed at the // root level Firefox puts brackets outside it. This is not the // case when a native object is printed as part of an array or // inside another object. sb.append('('); } sb.append('{'); if (level < 3) { final Object[] ids = obj.getIds(); if (ids != null && ids.length > 0) { boolean needsSeparator = false; for (Object key : ids) { if (needsSeparator) { sb.append(", "); } sb.append(key); sb.append(':'); appendValue(obj.get(key), sb, level + 1); needsSeparator = true; } } } sb.append('}'); if (level == 0) { sb.append(')'); } }
attaributes_ = Boolean.TRUE.equals(options.get("attributes")); attributeOldValue_ = Boolean.TRUE.equals(options.get("attributeOldValue")); characterData_ = Boolean.TRUE.equals(options.get("characterData")); characterDataOldValue_ = Boolean.TRUE.equals(options.get("characterDataOldValue")); subtree_ = Boolean.TRUE.equals(options.get("subtree")); attributeFilter_ = (NativeArray) options.get("attributeFilter"); final boolean childList = Boolean.TRUE.equals(options.get("childList"));
private static String formatToString(final Object o) { if (o == null) { return "null"; } else if (o instanceof NativeFunction) { return ((NativeFunction) o).toString(); } else if (o instanceof BaseFunction) { return "function " + ((BaseFunction) o).getFunctionName() + "\n" + " [native code]\n" + "}"; } else if (o instanceof NativeArray) { // If an array is embedded inside another array, just return // "[object Object]" return "[object Object]"; } else if (o instanceof Delegator) { return "[object " + ((Delegator) o).getDelegee().getClassName() + "]"; } else if (o instanceof NativeObject) { return "[object " + ((NativeObject) o).getClassName() + "]"; } else if (o instanceof SimpleScriptable) { return "[object " + ((SimpleScriptable) o).getClassName() + "]"; } else { return o.toString(); } }
Scriptable delegee; if (args.length == 0) { delegee = new NativeObject(); } else { delegee = ScriptRuntime.toObject(cx, scope, args[0]);
final Object obj = ((NativeObject) types).get("type", (NativeObject) types); if ("character".equals(obj)) { breakIterator_ = BreakIterator.getCharacterInstance(locale);
final Object obj = ((NativeObject) types).get("type", (NativeObject) types); if ("character".equals(obj)) { breakIterator_ = BreakIterator.getCharacterInstance(locale);
private static Promise create(final Scriptable thisObj, final Object[] args, final PromiseState state) { // fulfilled promises are returned if (args.length != 0 && args[0] instanceof Promise && state == PromiseState.FULFILLED) { return (Promise) args[0]; } final Promise promise; if (args.length > 0) { final Object arg = args[0]; if (arg instanceof NativeObject) { final NativeObject nativeObject = (NativeObject) arg; promise = new Promise(nativeObject.get("then", nativeObject)); } else { promise = new Promise(); promise.value_ = arg; promise.state_ = state; } } else { promise = new Promise(); promise.value_ = Undefined.instance; promise.state_ = state; } promise.setParentScope(thisObj.getParentScope()); promise.setPrototype(getWindow(thisObj).getPrototype(promise.getClass())); return promise; }