Refine search
/** * Optimized version of toString(Object) for numbers. */ public static String toString(double val) { return numberToString(val, 10); }
private void print(StringLiteral node) throws IOException { writer.append(node.getQuoteCharacter()); writer.append(ScriptRuntime.escapeString(node.getValue(), node.getQuoteCharacter())); writer.append(node.getQuoteCharacter()); }
private Object toScriptableItemMap(Iterator<?> iter) { Object[] args = (iter != null) ? new Object[] { iter } : null; return ScriptRuntime.newObject(Context.getCurrentContext(), this, ScriptableItemMap.CLASSNAME, args); }
public static EcmaError typeError0(String messageId) { String msg = getMessage0(messageId); return typeError(msg); }
/** * Call obj.[[Get]](id) */ public static Object getObjectElem(Object obj, Object elem, Context cx) { return getObjectElem(obj, elem, cx, getTopCallScope(cx)); }
public static RuntimeException notFoundError(Scriptable object, String property) { // XXX: use object to improve the error message String msg = getMessage1("msg.is.not.defined", property); throw constructError("ReferenceError", msg); }
String escaped = escapeString((String)value); StringBuffer sb = new StringBuffer(escaped.length() + 2); sb.append('\"'); return "-0"; return toString(d); return toString(value); Object v = ScriptableObject.getProperty(obj, "toSource"); if (v instanceof Function) { Function f = (Function)v; return toString(f.call(cx, scope, obj, emptyArgs)); return toString(value); warnAboutNonJSObject(value); return value.toString();
public static Object setName(Scriptable bound, Object value, Context cx, Scriptable scope, String id) { if (bound != null) { // TODO: we used to special-case XMLObject here, but putProperty // seems to work for E4X and it's better to optimize the common case ScriptableObject.putProperty(bound, id, value); } else { // "newname = 7;", where 'newname' has not yet // been defined, creates a new property in the // top scope unless strict mode is specified. if (cx.hasFeature(Context.FEATURE_STRICT_MODE) || cx.hasFeature(Context.FEATURE_STRICT_VARS)) { Context.reportWarning( ScriptRuntime.getMessage1("msg.assn.create.strict", id)); } // Find the top scope by walking up the scope chain. bound = ScriptableObject.getTopLevelScope(scope); if (cx.useDynamicScope) { bound = checkDynamicScope(cx.topCallScope, bound); } bound.put(id, bound, value); } return value; }
public static Object setDefaultNamespace(Object namespace, Context cx) { Scriptable scope = cx.currentActivationCall; if (scope == null) { scope = getTopCallScope(cx); } XMLLib xmlLib = currentXMLLib(cx); Object ns = xmlLib.toDefaultXmlNamespace(cx, namespace); // XXX : this should be in separated namesapce from Scriptable.get/put if (!scope.has(DEFAULT_NS_TAG, scope)) { // XXX: this is racy of cause ScriptableObject.defineProperty(scope, DEFAULT_NS_TAG, ns, ScriptableObject.PERMANENT | ScriptableObject.DONTENUM); } else { scope.put(DEFAULT_NS_TAG, scope, ns); } return Undefined.instance; }
throw ScriptRuntime.notFunctionError( ScriptRuntime.toString(callbackArg)); thisArg = ScriptRuntime.toObject(cx, scope, args[1]); long length = getLengthProperty(cx, thisObj); Scriptable array = ScriptRuntime.newObject(cx, scope, "Array", null); long j=0; for (long i=0; i < length; i++) { Object[] innerArgs = new Object[3]; Object elem = (i > Integer.MAX_VALUE) ? ScriptableObject.getProperty(thisObj, Long.toString(i)) : ScriptableObject.getProperty(thisObj, (int)i); if (elem == Scriptable.NOT_FOUND) { continue; innerArgs[1] = new Long(i); innerArgs[2] = thisObj; Object result = f.call(cx, parent, thisArg, innerArgs); switch (id) { case Id_every: if (!ScriptRuntime.toBoolean(result)) return Boolean.FALSE; break; case Id_filter: if (ScriptRuntime.toBoolean(result)) setElem(cx, array, j++, innerArgs[0]); break; case Id_forEach:
public static Object getObjectProp(Scriptable obj, String property, Context cx) { Object result = ScriptableObject.getProperty(obj, property); if (result == Scriptable.NOT_FOUND) { if (cx.hasFeature(Context.FEATURE_STRICT_MODE)) { Context.reportWarning(ScriptRuntime.getMessage1( "msg.ref.undefined.prop", property)); } result = Undefined.instance; } return result; }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { Scriptable s = ScriptableObject.getTopLevelScope(scope); mdata.arrayobj = ScriptRuntime.newObject(cx, s, "Array", null); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
/** * See ECMA 15.4.1,2 */ private static Object jsConstructor(Context cx, Scriptable scope, Object[] args) { if (args.length == 0) return new NativeArray(0); // Only use 1 arg as first element for version 1.2; for // any other version (including 1.3) follow ECMA and use it as // a length. if (cx.getLanguageVersion() == Context.VERSION_1_2) { return new NativeArray(args); } else { Object arg0 = args[0]; if (args.length > 1 || !(arg0 instanceof Number)) { return new NativeArray(args); } else { long len = ScriptRuntime.toUint32(arg0); if (len != ((Number)arg0).doubleValue()) { String msg = ScriptRuntime.getMessage0("msg.arraylength.bad"); throw ScriptRuntime.constructError("RangeError", msg); } return new NativeArray(len); } } }
long length = getLengthProperty(cx, thisObj); || cx.getLanguageVersion() < Context.VERSION_1_5; for (i = 0; i < length; i++) { if (i > 0) result.append(separator); Object elem = getRawElem(thisObj, i); if (elem == NOT_FOUND || (skipUndefinedAndNull && (elem == null || elem == Undefined.instance))) { result.append(ScriptRuntime.uneval(cx, scope, elem)); if (toSource) { result.append('\"'); result.append(ScriptRuntime.escapeString(s)); result.append('\"'); } else { Callable fun; Scriptable funThis; fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx); elem = fun.call(cx, scope, funThis, ScriptRuntime.emptyArgs); result.append(ScriptRuntime.toString(elem));
String s = ScriptRuntime.toString(args, 0); int radix = ScriptRuntime.toInt32(args, 1); do { c = s.charAt(start); if (!ScriptRuntime.isStrWhiteSpaceChar(c)) break; start++; double d = ScriptRuntime.stringToNumber(s, start, radix); return ScriptRuntime.wrapNumber(negative ? -d : d);
scope = getTopLevelScope(scope); Object result = ScriptRuntime.newObject(cx, scope, "Array", null); int argc = args.length; if (argc == 0) return result; long length = getLengthProperty(cx, thisObj); long begin = toSliceIndex(ScriptRuntime.toInteger(args[0]), length); argc--; count = length - begin; } else { double dcount = ScriptRuntime.toInteger(args[1]); if (dcount < 0) { count = 0; && (cx.getLanguageVersion() == Context.VERSION_1_2)) && cx.getLanguageVersion() == Context.VERSION_1_2)
private Scriptable js_slice(Context cx, Scriptable thisObj, Object[] args) { Scriptable scope = getTopLevelScope(this); Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null); long length = getLengthProperty(cx, thisObj); long begin, end; if (args.length == 0) { begin = 0; end = length; } else { begin = toSliceIndex(ScriptRuntime.toInteger(args[0]), length); if (args.length == 1) { end = length; } else { end = toSliceIndex(ScriptRuntime.toInteger(args[1]), length); } } for (long slot = begin; slot < end; slot++) { Object temp = getElem(cx, thisObj, slot); setElem(cx, result, slot - begin, temp); } return result; }
static EvaluatorException reportRuntimeError0(String messageId) { String msg = ScriptRuntime.getMessage0(messageId); return reportRuntimeError(msg); }
function = (Callable)thisObj; } else { Object value = thisObj.getDefaultValue(ScriptRuntime.FunctionClass); if (!(value instanceof Callable)) { throw ScriptRuntime.notFunctionError(value, thisObj); callThis = toObjectOrNull(cx, args[0]); callThis = getTopCallScope(cx); || arg1 instanceof Arguments) callArgs = cx.getElements((Scriptable) arg1); } else { throw ScriptRuntime.typeError0("msg.arg.isnt.array");
private RuntimeException reportClassFileFormatException( ScriptOrFnNode scriptOrFn, String message) { String msg = scriptOrFn instanceof FunctionNode ? ScriptRuntime.getMessage2("msg.while.compiling.fn", ((FunctionNode)scriptOrFn).getFunctionName(), message) : ScriptRuntime.getMessage1("msg.while.compiling.script", message); return Context.reportRuntimeError(msg, scriptOrFn.getSourceName(), scriptOrFn.getLineno(), null, 0); }