private void errorReporter(ExecutionContext cx, Throwable throwable) { try { throw throwable; } catch (StopExecutionException e) { if (e.getReason() == Reason.Quit) { System.exit(0); } } catch (ScriptException e) { handleException(cx.getRealm(), e); } catch (UnhandledRejectionException e) { handleException(cx.getRealm(), e); } catch (StackOverflowError e) { handleException(cx.getRealm(), e); } catch (OutOfMemoryError e) { handleException(cx.getRealm(), e); } catch (InternalException e) { handleException(e); } catch (BootstrapMethodError e) { handleException(e.getCause()); } catch (UncheckedIOException e) { handleException(e.getCause()); } catch (Throwable e) { printStackTrace(System.err, e, options.stacktraceDepth); System.exit(1); } }
/** * 19.4.2.1 Symbol.for (key) * * @param cx the execution context * @param thisValue the function this-value * @param key the symbol string key * @return the mapped symbol */ @Function(name = "for", arity = 1) public static Object _for(ExecutionContext cx, Object thisValue, Object key) { /* steps 1-2 */ String stringKey = ToFlatString(cx, key); /* steps 3-7 */ return cx.getRealm().getSymbolRegistry().getSymbol(stringKey); }
/** * 19.4.2.5 Symbol.keyFor (sym) * * @param cx the execution context * @param thisValue the function this-value * @param sym the global symbol * @return the symbol string key or undefined if the symbol is not in the registry */ @Function(name = "keyFor", arity = 1) public static Object keyFor(ExecutionContext cx, Object thisValue, Object sym) { /* step 1 */ if (!Type.isSymbol(sym)) { throw newTypeError(cx, Messages.Key.NotSymbol); } /* steps 2-3 */ String key = cx.getRealm().getSymbolRegistry().getKey(Type.symbolValue(sym)); /* step 4 */ return key != null ? key : UNDEFINED; }
/** * 9.2.3 FunctionAllocate (functionPrototype, strict [,functionKind] ) * * @param cx the execution context * @param functionPrototype the function prototype * @param strict the strict mode flag * @param kind the function kind * @return the new generator function object */ public static OrdinaryConstructorGenerator FunctionAllocate( ExecutionContext cx, ScriptObject functionPrototype, boolean strict, FunctionKind kind) { assert kind != FunctionKind.ClassConstructor; Realm realm = cx.getRealm(); /* steps 1-5 (implicit) */ /* steps 6-9 */ OrdinaryConstructorGenerator f = new OrdinaryConstructorGenerator(realm); /* steps 10-14 */ f.allocate(realm, functionPrototype, strict, kind, ConstructorKind.Derived); /* step 15 */ return f; }
/** * Creates a new Number object. * * @param cx the execution context * @param numberData the number value * @param prototype the prototype object * @return the new number object */ public static NumberObject NumberCreate( ExecutionContext cx, double numberData, ScriptObject prototype) { return new NumberObject(cx.getRealm(), numberData, prototype); }
/** * Creates a new Number object with the default %NumberPrototype% prototype object. * * @param cx the execution context * @param numberData the number value * @return the new number object */ public static NumberObject NumberCreate(ExecutionContext cx, double numberData) { return new NumberObject(cx.getRealm(), numberData, cx.getIntrinsic(Intrinsics.NumberPrototype)); }