jdk.nashorn.internal.objects.annotations.Constructor Java Examples

The following examples show how to use jdk.nashorn.internal.objects.annotations.Constructor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeRegExp.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.10.4
 *
 * Constructor
 *
 * @param isNew is the new operator used for instantiating this regexp
 * @param self  self reference
 * @param args  arguments (optional: pattern and flags)
 * @return new NativeRegExp
 */
@Constructor(arity = 2)
public static NativeRegExp constructor(final boolean isNew, final Object self, final Object... args) {
    if (args.length > 1) {
        return newRegExp(args[0], args[1]);
    } else if (args.length > 0) {
        return newRegExp(args[0], UNDEFINED);
    }

    return newRegExp(UNDEFINED, UNDEFINED);
}
 
Example #2
Source File: NativeFunction.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.3.2.1 new Function (p1, p2, ... , pn, body)
 *
 * Constructor
 *
 * @param newObj is the new operator used for constructing this function
 * @param self   self reference
 * @param args   arguments
 * @return new NativeFunction
 */
@Constructor(arity = 1)
public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append("(function (");
    final String funcBody;
    if (args.length > 0) {
        final StringBuilder paramListBuf = new StringBuilder();
        for (int i = 0; i < args.length - 1; i++) {
            paramListBuf.append(JSType.toString(args[i]));
            if (i < args.length - 2) {
                paramListBuf.append(",");
            }
        }

        // now convert function body to a string
        funcBody = JSType.toString(args[args.length - 1]);

        final String paramList = paramListBuf.toString();
        if (!paramList.isEmpty()) {
            checkFunctionParameters(paramList);
            sb.append(paramList);
        }
    } else {
        funcBody = null;
    }

    sb.append(") {\n");
    if (args.length > 0) {
        checkFunctionBody(funcBody);
        sb.append(funcBody);
        sb.append('\n');
    }
    sb.append("})");

    final Global global = Global.instance();
    final Context context = global.getContext();
    return (ScriptFunction)context.eval(global, sb.toString(), global, "<function>");
}
 
Example #3
Source File: NativeDate.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - ECMA 15.9.3.1 new Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param isNew is this Date constructed with the new operator
 * @param self  self reference
 * @param args  arguments
 * @return new Date
 */
@Constructor(arity = 7)
public static Object construct(final boolean isNew, final Object self, final Object... args) {
    if (! isNew) {
        return toStringImpl(new NativeDate(), FORMAT_DATE_TIME);
    }

    NativeDate result;
    switch (args.length) {
    case 0:
        result = new NativeDate();
        break;

    case 1:
        double num;
        final Object arg = JSType.toPrimitive(args[0]);
        if (JSType.isString(arg)) {
            num = parseDateString(arg.toString());
        } else {
            num = timeClip(JSType.toNumber(args[0]));
        }
        result = new NativeDate(num);
        break;

    default:
        result = new NativeDate(0);
        final double[] d = convertCtorArgs(args);
        if (d == null) {
            result.setTime(Double.NaN);
        } else {
            final double time = timeClip(utc(makeDate(d), result.getTimeZone()));
            result.setTime(time);
        }
        break;
     }

     return result;
}
 
Example #4
Source File: NativeArrayBuffer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param newObj is this invoked with new
 * @param self   self reference
 * @param args   arguments to constructor
 * @return new NativeArrayBuffer
 */
@Constructor(arity = 1)
public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) {
    if (!newObj) {
        throw typeError("constructor.requires.new", "ArrayBuffer");
    }

    if (args.length == 0) {
        return new NativeArrayBuffer(0);
    }

    return new NativeArrayBuffer(JSType.toInt32(args[0]));
}
 
Example #5
Source File: NativeBoolean.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.6.2.1 new Boolean (value)
 *
 * @param newObj is the new operator used to instantiate this NativeBoolean
 * @param self   self reference
 * @param value  value of boolean
 * @return the new NativeBoolean
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object value) {
    final boolean flag = JSType.toBoolean(value);

    if (newObj) {
        return new NativeBoolean(flag);
    }

    return flag;
}
 
Example #6
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.10.4
 *
 * Constructor
 *
 * @param isNew is the new operator used for instantiating this regexp
 * @param self  self reference
 * @param args  arguments (optional: pattern and flags)
 * @return new NativeRegExp
 */
@Constructor(arity = 2)
public static NativeRegExp constructor(final boolean isNew, final Object self, final Object... args) {
    if (args.length > 1) {
        return newRegExp(args[0], args[1]);
    } else if (args.length > 0) {
        return newRegExp(args[0], UNDEFINED);
    }

    return newRegExp(UNDEFINED, UNDEFINED);
}
 
Example #7
Source File: NativeObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value])
 *
 * Constructor
 *
 * @param newObj is the new object instantiated with the new operator
 * @param self   self reference
 * @param value  value of object to be instantiated
 * @return the new NativeObject
 */
@Constructor
public static Object construct(final boolean newObj, final Object self, final Object value) {
    final JSType type = JSType.ofNoFunction(value);

    // Object(null), Object(undefined), Object() are same as "new Object()"

    if (newObj || type == JSType.NULL || type == JSType.UNDEFINED) {
        switch (type) {
        case BOOLEAN:
        case NUMBER:
        case STRING:
            return Global.toObject(value);
        case OBJECT:
            return value;
        case NULL:
        case UNDEFINED:
            // fall through..
        default:
            break;
        }

        return Global.newEmptyInstance();
    }

    return Global.toObject(value);
}
 
Example #8
Source File: NativeObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value])
 *
 * Constructor
 *
 * @param newObj is the new object instantiated with the new operator
 * @param self   self reference
 * @param value  value of object to be instantiated
 * @return the new NativeObject
 */
@Constructor
public static Object construct(final boolean newObj, final Object self, final Object value) {
    final JSType type = JSType.ofNoFunction(value);

    // Object(null), Object(undefined), Object() are same as "new Object()"

    if (newObj || type == JSType.NULL || type == JSType.UNDEFINED) {
        switch (type) {
        case BOOLEAN:
        case NUMBER:
        case STRING:
            return Global.toObject(value);
        case OBJECT:
            return value;
        case NULL:
        case UNDEFINED:
            // fall through..
        default:
            break;
        }

        return Global.newEmptyInstance();
    }

    return Global.toObject(value);
}
 
Example #9
Source File: NativeDate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - ECMA 15.9.3.1 new Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param isNew is this Date constructed with the new operator
 * @param self  self reference
 * @param args  arguments
 * @return new Date
 */
@Constructor(arity = 7)
public static Object construct(final boolean isNew, final Object self, final Object... args) {
    if (! isNew) {
        return toStringImpl(new NativeDate(), FORMAT_DATE_TIME);
    }

    NativeDate result;
    switch (args.length) {
    case 0:
        result = new NativeDate();
        break;

    case 1:
        double num;
        final Object arg = JSType.toPrimitive(args[0]);
        if (JSType.isString(arg)) {
            num = parseDateString(arg.toString());
        } else {
            num = timeClip(JSType.toNumber(args[0]));
        }
        result = new NativeDate(num);
        break;

    default:
        result = new NativeDate(0);
        final double[] d = convertCtorArgs(args);
        if (d == null) {
            result.setTime(Double.NaN);
        } else {
            final double time = timeClip(utc(makeDate(d), result.getTimeZone()));
            result.setTime(time);
        }
        break;
     }

     return result;
}
 
Example #10
Source File: NativeBoolean.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.6.2.1 new Boolean (value)
 *
 * @param newObj is the new operator used to instantiate this NativeBoolean
 * @param self   self reference
 * @param value  value of boolean
 * @return the new NativeBoolean
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object value) {
    final boolean flag = JSType.toBoolean(value);

    if (newObj) {
        return new NativeBoolean(flag);
    }

    return flag;
}
 
Example #11
Source File: NativeBoolean.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.6.2.1 new Boolean (value)
 *
 * @param newObj is the new operator used to instantiate this NativeBoolean
 * @param self   self reference
 * @param value  value of boolean
 * @return the new NativeBoolean
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object value) {
    final boolean flag = JSType.toBoolean(value);

    if (newObj) {
        return new NativeBoolean(flag);
    }

    return flag;
}
 
Example #12
Source File: NativeObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value])
 *
 * Constructor
 *
 * @param newObj is the new object instantiated with the new operator
 * @param self   self reference
 * @param value  value of object to be instantiated
 * @return the new NativeObject
 */
@Constructor
public static Object construct(final boolean newObj, final Object self, final Object value) {
    final JSType type = JSType.ofNoFunction(value);

    // Object(null), Object(undefined), Object() are same as "new Object()"

    if (newObj || type == JSType.NULL || type == JSType.UNDEFINED) {
        switch (type) {
        case BOOLEAN:
        case NUMBER:
        case STRING:
            return Global.toObject(value);
        case OBJECT:
            return value;
        case NULL:
        case UNDEFINED:
            // fall through..
        default:
            break;
        }

        return Global.newEmptyInstance();
    }

    return Global.toObject(value);
}
 
Example #13
Source File: NativeDate.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - ECMA 15.9.3.1 new Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param isNew is this Date constructed with the new operator
 * @param self  self reference
 * @param args  arguments
 * @return new Date
 */
@Constructor(arity = 7)
public static Object construct(final boolean isNew, final Object self, final Object... args) {
    if (! isNew) {
        return toStringImpl(new NativeDate(), FORMAT_DATE_TIME);
    }

    NativeDate result;
    switch (args.length) {
    case 0:
        result = new NativeDate();
        break;

    case 1:
        double num;
        final Object arg = JSType.toPrimitive(args[0]);
        if (JSType.isString(arg)) {
            num = parseDateString(arg.toString());
        } else {
            num = timeClip(JSType.toNumber(args[0]));
        }
        result = new NativeDate(num);
        break;

    default:
        result = new NativeDate(0);
        final double[] d = convertCtorArgs(args);
        if (d == null) {
            result.setTime(Double.NaN);
        } else {
            final double time = timeClip(utc(makeDate(d), result.getTimeZone()));
            result.setTime(time);
        }
        break;
     }

     return result;
}
 
Example #14
Source File: NativeArrayBuffer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param newObj is this invoked with new
 * @param self   self reference
 * @param args   arguments to constructor
 * @return new NativeArrayBuffer
 */
@Constructor(arity = 1)
public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) {
    if (!newObj) {
        throw typeError("constructor.requires.new", "ArrayBuffer");
    }

    if (args.length == 0) {
        return new NativeArrayBuffer(0);
    }

    return new NativeArrayBuffer(JSType.toInt32(args[0]));
}
 
Example #15
Source File: NativeRegExp.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.10.4
 *
 * Constructor
 *
 * @param isNew is the new operator used for instantiating this regexp
 * @param self  self reference
 * @param args  arguments (optional: pattern and flags)
 * @return new NativeRegExp
 */
@Constructor(arity = 2)
public static NativeRegExp constructor(final boolean isNew, final Object self, final Object... args) {
    if (args.length > 1) {
        return newRegExp(args[0], args[1]);
    } else if (args.length > 0) {
        return newRegExp(args[0], UNDEFINED);
    }

    return newRegExp(UNDEFINED, UNDEFINED);
}
 
Example #16
Source File: NativeFunction.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.3.2.1 new Function (p1, p2, ... , pn, body)
 *
 * Constructor
 *
 * @param newObj is the new operator used for constructing this function
 * @param self   self reference
 * @param args   arguments
 * @return new NativeFunction
 */
@Constructor(arity = 1)
public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append("(function (");
    final String funcBody;
    if (args.length > 0) {
        final StringBuilder paramListBuf = new StringBuilder();
        for (int i = 0; i < args.length - 1; i++) {
            paramListBuf.append(JSType.toString(args[i]));
            if (i < args.length - 2) {
                paramListBuf.append(",");
            }
        }

        // now convert function body to a string
        funcBody = JSType.toString(args[args.length - 1]);

        final String paramList = paramListBuf.toString();
        if (!paramList.isEmpty()) {
            checkFunctionParameters(paramList);
            sb.append(paramList);
        }
    } else {
        funcBody = null;
    }

    sb.append(") {\n");
    if (args.length > 0) {
        checkFunctionBody(funcBody);
        sb.append(funcBody);
        sb.append('\n');
    }
    sb.append("})");

    final Global global = Global.instance();
    final Context context = global.getContext();
    return (ScriptFunction)context.eval(global, sb.toString(), global, "<function>");
}
 
Example #17
Source File: NativeFunction.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.3.2.1 new Function (p1, p2, ... , pn, body)
 *
 * Constructor
 *
 * @param newObj is the new operator used for constructing this function
 * @param self   self reference
 * @param args   arguments
 * @return new NativeFunction
 */
@Constructor(arity = 1)
public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append("(function (");
    final String funcBody;
    if (args.length > 0) {
        final StringBuilder paramListBuf = new StringBuilder();
        for (int i = 0; i < args.length - 1; i++) {
            paramListBuf.append(JSType.toString(args[i]));
            if (i < args.length - 2) {
                paramListBuf.append(",");
            }
        }

        // now convert function body to a string
        funcBody = JSType.toString(args[args.length - 1]);

        final String paramList = paramListBuf.toString();
        if (!paramList.isEmpty()) {
            checkFunctionParameters(paramList);
            sb.append(paramList);
        }
    } else {
        funcBody = null;
    }

    sb.append(") {\n");
    if (args.length > 0) {
        checkFunctionBody(funcBody);
        sb.append(funcBody);
        sb.append('\n');
    }
    sb.append("})");

    final Global global = Global.instance();
    final Context context = global.getContext();
    return (ScriptFunction)context.eval(global, sb.toString(), global, "<function>");
}
 
Example #18
Source File: NativeArrayBuffer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param newObj is this invoked with new
 * @param self   self reference
 * @param args   arguments to constructor
 * @return new NativeArrayBuffer
 */
@Constructor(arity = 1)
public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) {
    if (!newObj) {
        throw typeError("constructor.requires.new", "ArrayBuffer");
    }

    if (args.length == 0) {
        return new NativeArrayBuffer(0);
    }

    return new NativeArrayBuffer(JSType.toInt32(args[0]));
}
 
Example #19
Source File: NativeDataView.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example #20
Source File: NativeJSAdapter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param isNew is this NativeJSAdapter instantiated with the new operator
 * @param self  self reference
 * @param args  arguments ([adaptee], [overrides, adaptee] or [proto, overrides, adaptee]
 * @return new NativeJSAdapter
 */
@Constructor
public static NativeJSAdapter construct(final boolean isNew, final Object self, final Object... args) {
    Object proto     = UNDEFINED;
    Object overrides = UNDEFINED;
    Object adaptee;

    if (args == null || args.length == 0) {
        throw typeError("not.an.object", "null");
    }

    switch (args.length) {
    case 1:
        adaptee = args[0];
        break;

    case 2:
        overrides = args[0];
        adaptee   = args[1];
        break;

    default:
        //fallthru
    case 3:
        proto = args[0];
        overrides = args[1];
        adaptee = args[2];
        break;
    }

    if (!(adaptee instanceof ScriptObject)) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(adaptee));
    }

    final Global global = Global.instance();
    if (proto != null && !(proto instanceof ScriptObject)) {
        proto = global.getJSAdapterPrototype();
    }

    return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, $nasgenmap$);
}
 
Example #21
Source File: NativeJSAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param isNew is this NativeJSAdapter instantiated with the new operator
 * @param self  self reference
 * @param args  arguments ([adaptee], [overrides, adaptee] or [proto, overrides, adaptee]
 * @return new NativeJSAdapter
 */
@Constructor
public static NativeJSAdapter construct(final boolean isNew, final Object self, final Object... args) {
    Object proto     = UNDEFINED;
    Object overrides = UNDEFINED;
    Object adaptee;

    if (args == null || args.length == 0) {
        throw typeError("not.an.object", "null");
    }

    switch (args.length) {
    case 1:
        adaptee = args[0];
        break;

    case 2:
        overrides = args[0];
        adaptee   = args[1];
        break;

    default:
        //fallthru
    case 3:
        proto = args[0];
        overrides = args[1];
        adaptee = args[2];
        break;
    }

    if (!(adaptee instanceof ScriptObject)) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(adaptee));
    }

    final Global global = Global.instance();
    if (proto != null && !(proto instanceof ScriptObject)) {
        proto = global.getJSAdapterPrototype();
    }

    return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, $nasgenmap$);
}
 
Example #22
Source File: NativeDataView.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example #23
Source File: NativeDataView.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example #24
Source File: NativeJSAdapter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param isNew is this NativeJSAdapter instantiated with the new operator
 * @param self  self reference
 * @param args  arguments ([adaptee], [overrides, adaptee] or [proto, overrides, adaptee]
 * @return new NativeJSAdapter
 */
@Constructor
public static NativeJSAdapter construct(final boolean isNew, final Object self, final Object... args) {
    Object proto     = UNDEFINED;
    Object overrides = UNDEFINED;
    Object adaptee;

    if (args == null || args.length == 0) {
        throw typeError("not.an.object", "null");
    }

    switch (args.length) {
    case 1:
        adaptee = args[0];
        break;

    case 2:
        overrides = args[0];
        adaptee   = args[1];
        break;

    default:
        //fallthru
    case 3:
        proto = args[0];
        overrides = args[1];
        adaptee = args[2];
        break;
    }

    if (!(adaptee instanceof ScriptObject)) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(adaptee));
    }

    final Global global = Global.instance();
    if (proto != null && !(proto instanceof ScriptObject)) {
        proto = global.getJSAdapterPrototype();
    }

    return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, $nasgenmap$);
}
 
Example #25
Source File: NativeNumber.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * ECMA 15.7.2 - The Number constructor
 *
 * @param newObj is this Number instantiated with the new operator
 * @param self   self reference
 * @param args   value of number
 * @return the Number instance (internally represented as a {@code NativeNumber})
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object... args) {
    final double num = (args.length > 0) ? JSType.toNumber(args[0]) : 0.0;

    return newObj? new NativeNumber(num) : num;
}
 
Example #26
Source File: NativeNumber.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * ECMA 15.7.2 - The Number constructor
 *
 * @param newObj is this Number instantiated with the new operator
 * @param self   self reference
 * @param args   value of number
 * @return the Number instance (internally represented as a {@code NativeNumber})
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object... args) {
    final double num = (args.length > 0) ? JSType.toNumber(args[0]) : 0.0;

    return newObj? new NativeNumber(num) : num;
}
 
Example #27
Source File: NativeNumber.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * ECMA 15.7.2 - The Number constructor
 *
 * @param newObj is this Number instantiated with the new operator
 * @param self   self reference
 * @param args   value of number
 * @return the Number instance (internally represented as a {@code NativeNumber})
 */
@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object... args) {
    final double num = (args.length > 0) ? JSType.toNumber(args[0]) : 0.0;

    return newObj? new NativeNumber(num) : num;
}
 
Example #28
Source File: NativeJavaImporter.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor
 * @param isNew is the new operator used for instantiating this NativeJavaImporter
 * @param self self reference
 * @param args arguments
 * @return NativeJavaImporter instance
 */
@Constructor(arity = 1)
public static NativeJavaImporter constructor(final boolean isNew, final Object self, final Object... args) {
    return new NativeJavaImporter(args);
}
 
Example #29
Source File: NativeJavaImporter.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor
 * @param isNew is the new operator used for instantiating this NativeJavaImporter
 * @param self self reference
 * @param args arguments
 * @return NativeJavaImporter instance
 */
@Constructor(arity = 1)
public static NativeJavaImporter constructor(final boolean isNew, final Object self, final Object... args) {
    return new NativeJavaImporter(args);
}
 
Example #30
Source File: NativeInt16Array.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor
 *
 * @param newObj is this typed array instantiated with the new operator
 * @param self   self reference
 * @param args   args
 *
 * @return new typed array
 */
@Constructor(arity = 1)
public static NativeInt16Array constructor(final boolean newObj, final Object self, final Object... args) {
    return (NativeInt16Array)constructorImpl(newObj, args, FACTORY);
}