use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class AsyncGeneratorFunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param callerContext
* the caller execution context
* @param cx
* the execution context
* @param newTarget
* the newTarget constructor function
* @param args
* the function arguments
* @return the new async generator function object
*/
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.AsyncGenerator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.AsyncGenerator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.asyncGenerator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryAsyncGenerator f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class DateTimeFormatConstructor method ToDateTimeOptions.
/**
* 12.1.2 ToDateTimeOptions (options, required, defaults)
*
* @param cx
* the execution context
* @param opts
* the options object
* @param required
* the required date field
* @param defaults
* the default date field
* @return the date-time options script object
*/
public static ScriptObject ToDateTimeOptions(ExecutionContext cx, Object opts, String required, String defaults) {
/* steps 1-2 */
OrdinaryObject options = ObjectCreate(cx, Type.isUndefined(opts) ? null : ToObject(cx, opts));
/* step 3 */
boolean needDefaults = true;
/* step 4 */
if ("date".equals(required) || "any".equals(required)) {
// FIXME: spec vs. impl (short circuit after first undefined value?)
for (String prop : array("weekday", "year", "month", "day")) {
Object kvalue = Get(cx, options, prop);
if (!Type.isUndefined(kvalue)) {
needDefaults = false;
}
}
}
/* step 5 */
if ("time".equals(required) || "any".equals(required)) {
// FIXME: spec vs. impl (short circuit after first undefined value?)
for (String prop : array("hour", "minute", "second")) {
Object kvalue = Get(cx, options, prop);
if (!Type.isUndefined(kvalue)) {
needDefaults = false;
}
}
}
/* step 6 */
if (needDefaults && ("date".equals(defaults) || "all".equals(defaults))) {
for (String prop : array("year", "month", "day")) {
CreateDataPropertyOrThrow(cx, options, prop, "numeric");
}
}
/* step 7 */
if (needDefaults && ("time".equals(defaults) || "all".equals(defaults))) {
for (String prop : array("hour", "minute", "second")) {
CreateDataPropertyOrThrow(cx, options, prop, "numeric");
}
}
/* step 8 */
return options;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class DateTimeFormatConstructor method FormatToPartDateTime.
/**
* FormatToPartDateTime(dateTimeFormat, x)
*
* @param cx
* the execution context
* @param dateTimeFormat
* the date format object
* @param x
* the number value
* @return the formatted date-time object
*/
public static ArrayObject FormatToPartDateTime(ExecutionContext cx, DateTimeFormatObject dateTimeFormat, double x) {
if (Double.isInfinite(x) || Double.isNaN(x)) {
throw newRangeError(cx, Messages.Key.InvalidDateValue);
}
/* step 1 */
List<Map.Entry<String, String>> parts = CreateDateTimeParts(dateTimeFormat, new Date((long) x));
/* step 2 */
ArrayObject result = ArrayCreate(cx, 0);
/* step 3 */
int n = 0;
/* step 4 */
for (Map.Entry<String, String> part : parts) {
/* step 4.a */
OrdinaryObject o = ObjectCreate(cx, Intrinsics.ObjectPrototype);
/* steps 4.b-c */
CreateDataProperty(cx, o, "type", part.getKey());
/* steps 4.d-e */
CreateDataProperty(cx, o, "value", part.getValue());
/* steps 4.f-g */
CreateDataProperty(cx, result, n++, o);
}
/* step 5 */
return result;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class ErrorObject method getErrorObjectProperty.
/**
* Specialized property retrieval to prevent any script execution.
*
* @param error
* the error object
* @param propertyName
* the property key
* @param defaultValue
* the default value
* @return property string value
*/
private static String getErrorObjectProperty(ErrorObject error, String propertyName, String defaultValue) {
Property property = error.lookupOwnProperty(propertyName);
if (property == null) {
ScriptObject proto = error.getPrototype();
if (proto instanceof ErrorPrototype || proto instanceof NativeErrorPrototype) {
property = ((OrdinaryObject) proto).lookupOwnProperty(propertyName);
}
}
Object value = property != null && property.isDataDescriptor() ? property.getValue() : null;
if (value == null || Type.isUndefined(value)) {
return defaultValue;
}
// Prevent possible recursion
if (value instanceof ErrorObject) {
return "<error>";
}
return Objects.toString(value);
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class PropertyGenerator method visit.
@Override
public ValType visit(PropertyDefinitionsMethod node, CodeVisitor mv) {
MethodName method = codegen.compile(node, decorators != null, mv);
boolean hasResume = node.hasResumePoint();
mv.enterVariableScope();
Variable<OrdinaryObject> object = mv.newVariable("object", OrdinaryObject.class);
// stack: [<object>] -> []
mv.store(object);
// stack: [] -> []
// 0 = hint for stacktraces to omit this frame
mv.lineInfo(0);
if (hasResume) {
mv.callWithSuspend(method, object, decoratorsOrNull(mv));
} else {
mv.call(method, object, decoratorsOrNull(mv));
}
mv.exitVariableScope();
return null;
}
Aggregations