当前位置: 首页>>代码示例>>Java>>正文


Java ScriptObject.get方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject.get方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject.get方法的具体用法?Java ScriptObject.get怎么用?Java ScriptObject.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.ScriptObject的用法示例。


在下文中一共展示了ScriptObject.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInterfaceImplemented

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
private static boolean isInterfaceImplemented(final Class<?> iface, final ScriptObject sobj) {
    for (final Method method : iface.getMethods()) {
        // ignore methods of java.lang.Object class
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }

        // skip check for default methods - non-abstract, interface methods
        if (! Modifier.isAbstract(method.getModifiers())) {
            continue;
        }

        final Object obj = sobj.get(method.getName());
        if (! (obj instanceof ScriptFunction)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:NashornScriptEngine.java

示例2: fillFrom

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(WRITABLE)) {
        this.writable = JSType.toBoolean(sobj.get(WRITABLE));
    } else {
        delete(WRITABLE, false);
    }

    if (sobj.has(VALUE)) {
        this.value = sobj.get(VALUE);
    } else {
        delete(VALUE, false);
    }

    return this;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:DataPropertyDescriptor.java

示例3: reverse

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:NativeArray.java

示例4: toString

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.11.4.4 Error.prototype.toString ( )
 *
 * @param self  self reference
 *
 * @return this NativeError as a string
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toString(final Object self) {
    // Step 1 and 2 : check if 'self' is object it not throw TypeError
    final ScriptObject sobj = Global.checkObject(self);

    // Step 3 & 4 : get "name" and convert to String.
    // But if message is undefined make it "Error".
    Object name = sobj.get("name");
    if (name == UNDEFINED) {
        name = "Error";
    } else {
        name = JSType.toString(name);
    }

    // Steps 5, 6, & 7 : get "message" and convert to String.
    // if 'message' is undefined make it "" (empty String).
    Object msg = sobj.get("message");
    if (msg == UNDEFINED) {
        msg = "";
    } else {
        msg = JSType.toString(msg);
    }

    // Step 8 : if name is empty, return msg
    if (((String)name).isEmpty()) {
        return msg;
    }

    // Step 9 : if message is empty, return name
    if (((String)msg).isEmpty()) {
        return name;
    }
    // Step 10 : return name + ": " + msg
    return name + ": " + msg;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:43,代码来源:NativeError.java

示例5: pop

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, CALLSITE_STRICT);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, CALLSITE_STRICT);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:NativeArray.java

示例6: logEvent

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
private static void logEvent(final RuntimeEvent<?> event) {
    if (event != null) {
        final Global global = Context.getGlobal();
        if (global.has("Debug")) {
            final ScriptObject debug = (ScriptObject)global.get("Debug");
            final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
            ScriptRuntime.apply(addRuntimeEvent, debug, event);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DebugLogger.java

示例7: fillFrom

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
@Override
public PropertyDescriptor fillFrom(final ScriptObject sobj) {
    if (sobj.has(CONFIGURABLE)) {
        this.configurable = JSType.toBoolean(sobj.get(CONFIGURABLE));
    } else {
        delete(CONFIGURABLE, false);
    }

    if (sobj.has(ENUMERABLE)) {
        this.enumerable = JSType.toBoolean(sobj.get(ENUMERABLE));
    } else {
        delete(ENUMERABLE, false);
    }

    if (sobj.has(GET)) {
        final Object getter = sobj.get(GET);
        if (getter == UNDEFINED || getter instanceof ScriptFunction) {
            this.get = getter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
        }
    } else {
        delete(GET, false);
    }

    if (sobj.has(SET)) {
        final Object setter = sobj.get(SET);
        if (setter == UNDEFINED || setter instanceof ScriptFunction) {
            this.set = setter;
        } else {
            throw typeError("not.a.function", ScriptRuntime.safeToString(setter));
        }
    } else {
        delete(SET, false);
    }

    return this;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AccessorPropertyDescriptor.java

示例8: shift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:NativeArray.java

示例9: unshift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self  self reference
 * @param items items for unshift
 * @return unshifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object unshift(final Object self, final Object... items) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final ScriptObject sobj   = (ScriptObject)obj;
    final long         len    = JSType.toUint32(sobj.getLength());

    if (items == null) {
        return ScriptRuntime.UNDEFINED;
    }

    if (bulkable(sobj)) {
        sobj.getArray().shiftRight(items.length);

        for (int j = 0; j < items.length; j++) {
            sobj.setArray(sobj.getArray().set(j, items[j], true));
        }
    } else {
        for (long k = len; k > 0; k--) {
            final long from = k - 1;
            final long to = k + items.length - 1;

            if (sobj.has(from)) {
                final Object fromValue = sobj.get(from);
                sobj.set(to, fromValue, CALLSITE_STRICT);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
            sobj.set(j, items[j], CALLSITE_STRICT);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, CALLSITE_STRICT);

    return newLength;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:52,代码来源:NativeArray.java

示例10: unshift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self  self reference
 * @param items items for unshift
 * @return unshifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object unshift(final Object self, final Object... items) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final ScriptObject sobj   = (ScriptObject)obj;
    final long         len    = JSType.toUint32(sobj.getLength());

    if (items == null) {
        return ScriptRuntime.UNDEFINED;
    }

    if (bulkable(sobj)) {
        sobj.getArray().shiftRight(items.length);

        for (int j = 0; j < items.length; j++) {
            sobj.setArray(sobj.getArray().set(j, items[j], true));
        }
    } else {
        for (long k = len; k > 0; k--) {
            final long from = k - 1;
            final long to = k + items.length - 1;

            if (sobj.has(from)) {
                final Object fromValue = sobj.get(from);
                sobj.set(to, fromValue, CALLSITE_STRICT);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
            sobj.set(j, items[j], CALLSITE_STRICT);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, CALLSITE_STRICT);

    return JSType.toNarrowestNumber(newLength);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:NativeArray.java

示例11: printObject

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
private void printObject(final PrintWriter out, final Object arg) {
    if (!getNashornDescriptor().isTraceObjects()) {
        out.print((arg instanceof ScriptObject) ? "ScriptObject" : arg);
        return;
    }

    if (arg instanceof ScriptObject) {
        final ScriptObject object = (ScriptObject)arg;

        boolean isFirst = true;
        final Set<Object> keySet = object.keySet();

        if (keySet.isEmpty()) {
            out.print(ScriptRuntime.safeToString(arg));
        } else {
            out.print("{ ");

            for (final Object key : keySet) {
                if (!isFirst) {
                    out.print(", ");
                }

                out.print(key);
                out.print(":");

                final Object value = object.get(key);

                if (value instanceof ScriptObject) {
                    out.print("...");
                } else {
                    printObject(out, value);
                }

                isFirst = false;
            }

            out.print(" }");
        }
     } else {
        out.print(ScriptRuntime.safeToString(arg));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:LinkerCallSite.java

示例12: getLineNumber

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * Nashorn extension: Error.prototype.lineNumber
 *
 * @param self self reference
 *
 * @return line number from which error was thrown
 */
public static Object getLineNumber(final Object self) {
    final ScriptObject sobj = Global.checkObject(self);
    return sobj.has(LINENUMBER) ? sobj.get(LINENUMBER) : ECMAException.getLineNumber(sobj);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:NativeError.java

示例13: getFileName

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * Nashorn extension: Error.prototype.fileName
 *
 * @param self self reference
 *
 * @return file name from which error was thrown
 */
public static Object getFileName(final Object self) {
    final ScriptObject sobj = Global.checkObject(self);
    return sobj.has(FILENAME) ? sobj.get(FILENAME) : ECMAException.getFileName((ScriptObject)self);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:NativeError.java

示例14: getColumnNumber

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * Nashorn extension: Error.prototype.columnNumber
 *
 * @param self self reference
 *
 * @return column number from which error was thrown
 */
public static Object getColumnNumber(final Object self) {
    final ScriptObject sobj = Global.checkObject(self);
    return sobj.has(COLUMNNUMBER) ? sobj.get(COLUMNNUMBER) : ECMAException.getColumnNumber((ScriptObject)self);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:NativeError.java


注:本文中的jdk.nashorn.internal.runtime.ScriptObject.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。