Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
  /** 23.4.1.1 WeakSet ([ iterable ]) */
  @Override
  public WeakSetObject construct(
      ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);

    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakSetObject set =
        OrdinaryCreateFromConstructor(
            calleeContext, newTarget, Intrinsics.WeakSetPrototype, WeakSetObjectAllocator.INSTANCE);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
      return set;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, set, "add");
    if (!IsCallable(_adder)) {
      throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "add");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
      while (iter.hasNext()) {
        Object nextValue = iter.next();
        adder.call(calleeContext, set, nextValue);
      }
      return set;
    } catch (ScriptException e) {
      iter.close(e);
      throw e;
    }
  }
Esempio n. 3
0
 /** 19.4.1.1 Symbol ( [ description ] ) */
 @Override
 public Symbol call(ExecutionContext callerContext, Object thisValue, Object... args) {
   ExecutionContext calleeContext = calleeContext();
   Object description = argument(args, 0);
   /* step 1 (not applicable) */
   /* steps 2-4 */
   String descString =
       Type.isUndefined(description) ? null : ToFlatString(calleeContext, description);
   /* step 5 */
   return new Symbol(descString);
 }