use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class CollatorConstructor method InitializeCollator.
/**
* 10.1.1 InitializeCollator (collator, locales, options)
*
* @param cx
* the execution context
* @param collator
* the collator object
* @param locales
* the locales array
* @param opts
* the options object
*/
public static void InitializeCollator(ExecutionContext cx, CollatorObject collator, Object locales, Object opts) {
/* steps 1-2 (FIXME: spec bug - unnecessary internal slot) */
/* step 3 */
Set<String> requestedLocals = CanonicalizeLocaleList(cx, locales);
/* steps 4-5 */
ScriptObject options;
if (Type.isUndefined(opts)) {
options = ObjectCreate(cx, Intrinsics.ObjectPrototype);
} else {
options = ToObject(cx, opts);
}
/* step 6 */
String u = GetStringOption(cx, options, "usage", set("sort", "search"), "sort");
/* step 7 */
collator.setUsage(u);
/* steps 8-9 */
CollatorLocaleData localeData = new CollatorLocaleData(u);
/* step 11 */
String matcher = GetStringOption(cx, options, "localeMatcher", set("lookup", "best fit"), "best fit");
/* steps 10, 12 */
OptionsRecord opt = new OptionsRecord(OptionsRecord.MatcherType.forName(matcher));
// FIXME: spec should propably define exact iteration order here
/* step 13 (kn-numeric) */
Boolean numeric = GetBooleanOption(cx, options, "numeric", null);
if (numeric != null) {
opt.set(ExtensionKey.kn, numeric.toString());
}
/* step 13 (kf-caseFirst) */
String caseFirst = GetStringOption(cx, options, "caseFirst", set("upper", "lower", "false"), null);
if (caseFirst != null) {
opt.set(ExtensionKey.kf, caseFirst);
}
/* steps 14-15 */
ResolvedLocale r = ResolveLocale(cx.getRealm(), getAvailableLocalesLazy(cx), requestedLocals, opt, relevantExtensionKeys, localeData);
/* step 16 */
collator.setLocale(r.getLocale());
/* steps 17-20 (co-collation) */
String collation = r.getValue(ExtensionKey.co);
collator.setCollation(collation != null ? collation : "default");
/* steps 17-20 (kn-numeric) */
collator.setNumeric("true".equals(r.getValue(ExtensionKey.kn)));
/* steps 17-20 (kf-caseFirst) */
collator.setCaseFirst(r.getValue(ExtensionKey.kf));
/* step 21 */
String s = GetStringOption(cx, options, "sensitivity", set("base", "accent", "case", "variant"), null);
/* step 22 */
if (s == null) {
// The specification differentiates between "sort" and "search" usage, but effectively
// you'll end up with "variant" in both cases, so take the short path here.
s = "variant";
}
/* step 23 */
collator.setSensitivity(s);
/* step 24 */
boolean ip = GetBooleanOption(cx, options, "ignorePunctuation", false);
/* step 25 */
collator.setIgnorePunctuation(ip);
/* step 26 */
collator.setBoundCompare(null);
/* step 27 (FIXME: spec bug - unnecessary internal slot) */
/* step 28 (omitted) */
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class PromiseAbstractOperations method NewPromiseCapability.
/**
* <h2>25.4.1 Promise Abstract Operations</h2>
* <p>
* 25.4.1.5 NewPromiseCapability ( C )
*
* @param cx
* the execution context
* @param c
* the promise constructor function
* @return the new promise capability record
*/
public static PromiseCapability<ScriptObject> NewPromiseCapability(ExecutionContext cx, Constructor c) {
/* steps 1-2 (not applicable) */
/* step 3 (moved) */
/* steps 4-5 */
GetCapabilitiesExecutor executor = new GetCapabilitiesExecutor(cx.getRealm());
/* steps 6-7 */
ScriptObject promise = c.construct(cx, c, executor);
/* step 8 */
Object resolve = executor.resolve.get();
if (!IsCallable(resolve)) {
throw newTypeError(cx, Messages.Key.NotCallable);
}
/* step 9 */
Object reject = executor.reject.get();
if (!IsCallable(reject)) {
throw newTypeError(cx, Messages.Key.NotCallable);
}
/* steps 3, 10-11 */
return new PromiseCapability<>(promise, (Callable) resolve, (Callable) reject);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class PromiseConstructor method PerformPromiseAll.
/**
* 25.4.4.1.1 Runtime Semantics: PerformPromiseAll( iteratorRecord, constructor,
* resultCapability)
*
* @param <PROMISE>
* the promise type
* @param cx
* the execution context
* @param iterator
* the iterator object
* @param constructor
* the constructor object
* @param resultCapability
* the new promise capability record
* @return the new promise object
*/
public static <PROMISE extends ScriptObject> PROMISE PerformPromiseAll(ExecutionContext cx, ScriptIterator<?> iterator, ScriptObject constructor, PromiseCapability<PROMISE> resultCapability) {
/* steps 1-2 (not applicable) */
/* step 3 */
ArrayList<Object> values = new ArrayList<>();
/* step 4 */
AtomicInteger remainingElementsCount = new AtomicInteger(1);
/* step 5 */
int index = 0;
/* step 6 */
while (iterator.hasNext()) {
/* steps 6.a-c, 6.e-g */
Object nextValue = iterator.next();
/* step 6.h */
// Using 'null' instead of undefined to be able to verify that no values are overwritten
values.add(null);
/* steps 6.i-j */
Object nextPromise = Invoke(cx, constructor, "resolve", nextValue);
/* steps 6.k-p */
PromiseAllResolveElementFunction resolveElement = new PromiseAllResolveElementFunction(cx.getRealm(), new AtomicBoolean(false), index, values, resultCapability, remainingElementsCount);
/* step 6.q */
remainingElementsCount.incrementAndGet();
/* steps 6.r-s */
Invoke(cx, nextPromise, "then", resolveElement, resultCapability.getReject());
/* step 6.t */
index += 1;
}
/* step 6.d */
if (remainingElementsCount.decrementAndGet() == 0) {
ArrayObject valuesArray = CreateArrayFromList(cx, values);
resultCapability.getResolve().call(cx, UNDEFINED, valuesArray);
}
return resultCapability.getPromise();
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class PromiseConstructor method PerformPromiseRace.
/**
* 25.4.4.3.1 Runtime Semantics: PerformPromiseRace ( iteratorRecord, promiseCapability, C )
*
* @param <PROMISE>
* the promise type
* @param cx
* the execution context
* @param iterator
* the iterator object
* @param constructor
* the constructor object
* @param promiseCapability
* the new promise capability record
* @return the new promise object
*/
public static <PROMISE extends ScriptObject> PROMISE PerformPromiseRace(ExecutionContext cx, ScriptIterator<?> iterator, ScriptObject constructor, PromiseCapability<PROMISE> promiseCapability) {
/* step 1 */
while (iterator.hasNext()) {
/* steps 1.a-c, 1.e-g */
Object nextValue = iterator.next();
/* steps 1.f-g */
Object nextPromise = Invoke(cx, constructor, "resolve", nextValue);
/* steps 1.h-i */
Invoke(cx, nextPromise, "then", promiseCapability.getResolve(), promiseCapability.getReject());
}
/* step 1.d */
return promiseCapability.getPromise();
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class RegExpConstructor method call.
/**
* 21.2.3.1 RegExp(pattern, flags)
*/
@Override
public ScriptObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object pattern = argument(args, 0);
Object flags = argument(args, 1);
/* steps 1-2 */
boolean patternIsRegExp = IsRegExp(calleeContext, pattern);
/* step 4 */
if (patternIsRegExp && Type.isUndefined(flags)) {
ScriptObject patternObject = Type.objectValue(pattern);
Object patternConstructor = Get(calleeContext, patternObject, "constructor");
if (this == patternConstructor) {
// SameValue
return patternObject;
}
}
/* steps 5-10 */
return RegExpCreate(calleeContext, this, pattern, flags, patternIsRegExp);
}
Aggregations