@Override public Scriptable createObject(Context cx, Scriptable scope) { if (useCallAsConstructor) { return null; } // Throw error if not explicitly coded to be used as constructor, // to satisfy ECMAScript standard (see bugzilla 202019). // To follow current (2003-05-01) SpiderMonkey behavior, change it to: // return super.createObject(cx, scope); throw ScriptRuntime.typeError1("msg.not.ctor", functionName); }
protected Scriptable ensureScriptable(Object arg) { if ( !(arg instanceof Scriptable) ) throw ScriptRuntime.typeError1("msg.arg.not.object", ScriptRuntime.typeof(arg)); return (Scriptable) arg; }
protected ScriptableObject ensureScriptableObject(Object arg) { if ( !(arg instanceof ScriptableObject) ) throw ScriptRuntime.typeError1("msg.arg.not.object", ScriptRuntime.typeof(arg)); return (ScriptableObject) arg; }
private static RuntimeException notXmlError(Object value) { throw typeError1("msg.isnt.xml.object", toString(value)); }
/** * Utility method to construct type error to indicate incompatible call * when converting script thisObj to a particular type is not possible. * Possible usage would be to have a private function like realThis: * <pre> * private static NativeSomething realThis(Scriptable thisObj, * IdFunctionObject f) * { * if (!(thisObj instanceof NativeSomething)) * throw incompatibleCallError(f); * return (NativeSomething)thisObj; * } * </pre> * Note that although such function can be implemented universally via * java.lang.Class.isInstance(), it would be much more slower. * @param f function that is attempting to convert 'this' * object. * @return Scriptable object suitable for a check by the instanceof * operator. * @throws RuntimeException if no more instanceof target can be found */ protected static EcmaError incompatibleCallError(IdFunctionObject f) { throw ScriptRuntime.typeError1("msg.incompat.call", f.getFunctionName()); }
private BaseFunction realFunction(Scriptable thisObj, IdFunctionObject f) { Object x = thisObj.getDefaultValue(ScriptRuntime.FunctionClass); if (x instanceof BaseFunction) { return (BaseFunction)x; } throw ScriptRuntime.typeError1("msg.incompat.call", f.getFunctionName()); }
public static RuntimeException notFunctionError(Object value, Object messageHelper) { // Use value for better error reporting String msg = (messageHelper == null) ? "null" : messageHelper.toString(); if (value == Scriptable.NOT_FOUND) { return typeError1("msg.function.not.found", msg); } return typeError2("msg.isnt.function", msg, typeof(value)); }
public static Scriptable enterWith(Object obj, Context cx, Scriptable scope) { Scriptable sobj = toObjectOrNull(cx, obj); if (sobj == null) { throw typeError1("msg.undef.with", toString(obj)); } if (sobj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)sobj; return xmlObject.enterWith(scope); } return new NativeWith(scope, sobj); }
/** * Implements the instanceof operator for JavaScript Function objects. * <p> * <code> * foo = new Foo();<br> * foo instanceof Foo; // true<br> * </code> * * @param instance The value that appeared on the LHS of the instanceof * operator * @return true if the "prototype" property of "this" appears in * value's prototype chain * */ @Override public boolean hasInstance(Scriptable instance) { Object protoProp = ScriptableObject.getProperty(this, "prototype"); if (protoProp instanceof Scriptable) { return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp); } throw ScriptRuntime.typeError1("msg.instanceof.bad.prototype", getFunctionName()); }
if (Boolean.FALSE.equals(current.get("configurable")) ) { if (Boolean.TRUE.equals(tryBoolean(getProperty(desc, "configurable")))) throw ScriptRuntime.typeError1("msg.change.configurable.false.to.true", name); if (changes(current.get("enumerable"), tryBoolean(getProperty(desc, "enumerable")))) throw ScriptRuntime.typeError1("msg.change.enumerable.with.configurable.false", name); if (Boolean.FALSE.equals(current.get("writable"))) { if (Boolean.TRUE.equals(tryBoolean(getProperty(desc, "writable")))) throw ScriptRuntime.typeError1("msg.change.writable.false.to.true.with.configurable.false", name); throw ScriptRuntime.typeError1("msg.change.value.with.writable.false", name); throw ScriptRuntime.typeError1("msg.change.setter.with.configurable.false", name); throw ScriptRuntime.typeError1("msg.change.getter.with.configurable.false", name); } else { if (isDataDescriptor(current)) throw ScriptRuntime.typeError1("msg.change.property.data.to.accessor.with.configurable.false", name); else throw ScriptRuntime.typeError1("msg.change.property.accessor.to.data.with.configurable.false", name);
public static Object newSpecial(Context cx, Object fun, Object[] args, Scriptable scope, int callType) { if (callType == Node.SPECIALCALL_EVAL) { if (NativeGlobal.isEvalFunction(fun)) { throw typeError1("msg.not.ctor", "eval"); } } else if (callType == Node.SPECIALCALL_WITH) { if (NativeWith.isWithFunction(fun)) { return NativeWith.newWithSpecial(cx, scope, args); } } else { throw Kit.codeBug(); } return newObject(fun, cx, scope, args); }
throw ScriptRuntime.typeError1("msg.default.value", arg);
throw ScriptRuntime.typeError1("msg.incompat.call", functionName);
args[0] == Undefined.instance) throw ScriptRuntime.typeError1("msg.no.properties", ScriptRuntime.toString(args[0]));
throw ScriptRuntime.typeError1("msg.set.prop.no.setter", name);