final void checkNotReadonly() { if ((attributes & READONLY) != 0) { String str = (name != null ? name : Integer.toString(indexOrHash)); throw Context.reportRuntimeError1("msg.modify.readonly", str); } }
@Override public void put(String id, Scriptable start, Object value) { // Ignore assignments to "length"--it's readonly. if (!id.equals("length")) throw Context.reportRuntimeError1( "msg.java.array.member.not.found", id); }
private static RuntimeException errorWithClassName(String msg, Object val) { return Context.reportRuntimeError1(msg, val.getClass().getName()); }
static Function getExistingCtor(Context cx, Scriptable scope, String constructorName) { Object ctorVal = ScriptableObject.getProperty(scope, constructorName); if (ctorVal instanceof Function) { return (Function)ctorVal; } if (ctorVal == Scriptable.NOT_FOUND) { throw Context.reportRuntimeError1( "msg.ctor.not.found", constructorName); } else { throw Context.reportRuntimeError1( "msg.not.ctor", constructorName); } }
private void checkNotSealed(String name, int index) { if (!isSealed()) return; String str = (name != null) ? name : Integer.toString(index); throw Context.reportRuntimeError1("msg.modify.sealed", str); }
private Slot findAttributeSlot(String name, int index, int accessType) { Slot slot = getSlot(name, index, accessType); if (slot == null) { String str = (name != null ? name : Integer.toString(index)); throw Context.reportRuntimeError1("msg.prop.not.found", str); } return slot; }
/** * If hasProperty(obj, name) would return true, then if the property that * was found is compatible with the new property, this method just returns. * If the property is not compatible, then an exception is thrown. * * A property redefinition is incompatible if the first definition was a * const declaration or if this one is. They are compatible only if neither * was const. */ public static void redefineProperty(Scriptable obj, String name, boolean isConst) { Scriptable base = getBase(obj, name); if (base == null) return; if (base instanceof ConstProperties) { ConstProperties cp = (ConstProperties)base; if (cp.isConst(name)) throw Context.reportRuntimeError1("msg.const.redecl", name); } if (isConst) throw Context.reportRuntimeError1("msg.var.redecl", name); } /**
private void importClass(NativeJavaClass cl) { String s = cl.getClassObject().getName(); String n = s.substring(s.lastIndexOf('.')+1); Object val = get(n, this); if (val != NOT_FOUND && val != cl) { throw Context.reportRuntimeError1("msg.prop.defined", n); } //defineProperty(n, cl, DONTENUM); put(n, this, cl); }
/** * @deprecated Use {@link #getTypeTag(Class)} * and {@link #convertArg(Context, Scriptable, Object, int)} * for type conversion. */ public static Object convertArg(Context cx, Scriptable scope, Object arg, Class<?> desired) { int tag = getTypeTag(desired); if (tag == JAVA_UNSUPPORTED_TYPE) { throw Context.reportRuntimeError1 ("msg.cant.convert", desired.getName()); } return convertArg(cx, scope, arg, tag); }
private Object js_importClass(Object[] args) { for (int i = 0; i != args.length; i++) { Object arg = args[i]; if (!(arg instanceof NativeJavaClass)) { throw Context.reportRuntimeError1( "msg.not.class", Context.toString(arg)); } importClass((NativeJavaClass)arg); } return Undefined.instance; }
private Object js_importPackage(Object[] args) { for (int i = 0; i != args.length; i++) { Object arg = args[i]; if (!(arg instanceof NativeJavaPackage)) { throw Context.reportRuntimeError1( "msg.not.pkg", Context.toString(arg)); } importPackage((NativeJavaPackage)arg); } return Undefined.instance; }
public static String numberToString(double d, int base) { if (d != d) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { StringBuffer result = new StringBuffer(); DToA.JS_dtostr(result, DToA.DTOSTR_STANDARD, 0, d); return result.toString(); } }
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (f.hasTag(FTAG)) { if (f.methodId() == Id_constructor) { throw Context.reportRuntimeError1("msg.cant.call.indirect", "With"); } } throw f.unknown(); }
@Override public Object getDefaultValue(Class<?> hint) { if (hint == ScriptRuntime.FunctionClass) return this; Object rval; Class<?> type; try { rval = field.get(javaObject); type = field.getType(); } catch (IllegalAccessException accEx) { throw Context.reportRuntimeError1( "msg.java.internal.private", field.getName()); } Context cx = Context.getContext(); rval = cx.getWrapFactory().wrap(cx, this, rval, type); if (rval instanceof Scriptable) { rval = ((Scriptable) rval).getDefaultValue(hint); } return rval; }
JavaMembers(Scriptable scope, Class<?> cl, boolean includeProtected) { try { Context cx = ContextFactory.getGlobal().enterContext(); ClassShutter shutter = cx.getClassShutter(); if (shutter != null && !shutter.visibleToScripts(cl.getName())) { throw Context.reportRuntimeError1("msg.access.prohibited", cl.getName()); } this.includePrivate = cx.hasFeature( Context.FEATURE_ENHANCED_JAVA_ACCESS); this.members = new HashMap<String,Object>(); this.staticMembers = new HashMap<String,Object>(); this.cl = cl; reflect(scope, includeProtected); } finally { Context.exit(); } }
@Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!f.hasTag(CALL_TAG)) { return super.execIdCall(f, cx, scope, thisObj, args); } int id = f.methodId(); if (id == Id_constructor) { if (thisObj != null) { throw Context.reportRuntimeError1("msg.only.from.new", "Call"); } ScriptRuntime.checkDeprecated(cx, "Call"); NativeCall result = new NativeCall(); result.setPrototype(getObjectPrototype(scope)); return result; } throw new IllegalArgumentException(String.valueOf(id)); }
if (info != 0) { if (start == this && isSealed()) { throw Context.reportRuntimeError1("msg.modify.sealed", name); if (id != 0) { if (start == this && isSealed()) { throw Context.reportRuntimeError1("msg.modify.sealed", name);
public static Object callSpecial(Context cx, Callable fun, Scriptable thisObj, Object[] args, Scriptable scope, Scriptable callerThis, int callType, String filename, int lineNumber) { if (callType == Node.SPECIALCALL_EVAL) { if (NativeGlobal.isEvalFunction(fun)) { return evalSpecial(cx, scope, callerThis, args, filename, lineNumber); } } else if (callType == Node.SPECIALCALL_WITH) { if (NativeWith.isWithFunction(fun)) { throw Context.reportRuntimeError1("msg.only.from.new", "With"); } } else { throw Kit.codeBug(); } return fun.call(cx, scope, thisObj, args); }
private Object js_construct(Scriptable scope, Object[] args) { ImporterTopLevel result = new ImporterTopLevel(); for (int i = 0; i != args.length; ++i) { Object arg = args[i]; if (arg instanceof NativeJavaClass) { result.importClass((NativeJavaClass)arg); } else if (arg instanceof NativeJavaPackage) { result.importPackage((NativeJavaPackage)arg); } else { throw Context.reportRuntimeError1( "msg.not.class.not.pkg", Context.toString(arg)); } } // set explicitly prototype and scope // as otherwise in top scope mode BaseFunction.construct // would keep them set to null. It also allow to use // JavaImporter without new and still get properly // initialized object. result.setParentScope(scope); result.setPrototype(this); return result; }
do { if (search == target) { throw Context.reportRuntimeError1( "msg.cyclic.value", name);