Search in sources :

Example 1 with RegExpObject

use of com.github.anba.es6draft.runtime.objects.text.RegExpObject in project es6draft by anba.

the class SourceBuilder method source.

private String source(ExecutionContext cx, HashSet<ScriptObject> stack, Object value) {
    switch(Type.of(value)) {
        case Null:
            return "null";
        case Boolean:
            return Type.booleanValue(value) ? "true" : "false";
        case String:
            return Strings.quote(Type.stringValue(value).toString());
        case Symbol:
            return Type.symbolValue(value).toString();
        case Number:
            return ToFlatString(cx, value);
        case SIMD:
            return Type.simdValue(value).toString();
        case Object:
            ScriptObject objValue = Type.objectValue(value);
            if (IsCallable(objValue)) {
                return ((Callable) objValue).toSource(cx);
            }
            if (stack.contains(objValue) || stack.size() > maxStackDepth) {
                return "« ... »";
            }
            stack.add(objValue);
            try {
                if (objValue instanceof DateObject) {
                    return DatePrototype.Properties.toString(cx, value).toString();
                } else if (objValue instanceof RegExpObject) {
                    return RegExpPrototype.Properties.toString(cx, value).toString();
                } else if (objValue instanceof ArrayObject) {
                    return arrayToSource(cx, stack, objValue);
                } else {
                    return objectToSource(cx, stack, objValue);
                }
            } finally {
                stack.remove(objValue);
            }
        case Undefined:
        default:
            return "(void 0)";
    }
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable) DateObject(com.github.anba.es6draft.runtime.objects.date.DateObject)

Example 2 with RegExpObject

use of com.github.anba.es6draft.runtime.objects.text.RegExpObject in project es6draft by anba.

the class ReflectParser method visit.

@Override
public Object visit(RegularExpressionLiteral node, Void value) {
    RegExpObject _value = RegExpCreate(cx, node.getRegexp(), node.getFlags());
    if (hasBuilder(Type.Literal)) {
        return call(Type.Literal, node, _value);
    }
    OrdinaryObject expression = createExpression(node, Type.Literal);
    addProperty(expression, "value", _value);
    return expression;
}
Also used : RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Aggregations

RegExpObject (com.github.anba.es6draft.runtime.objects.text.RegExpObject)2 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)1 DateObject (com.github.anba.es6draft.runtime.objects.date.DateObject)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1