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


Java JSObject类代码示例

本文整理汇总了Java中jdk.nashorn.api.scripting.JSObject的典型用法代码示例。如果您正苦于以下问题:Java JSObject类的具体用法?Java JSObject怎么用?Java JSObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: call

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
/**
 * ECMA 15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, ... ] ] )
 *
 * @param self self reference
 * @param args arguments for call
 * @return result of call
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object call(final Object self, final Object... args) {
    checkCallable(self);

    final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
    Object[] arguments;

    if (args.length > 1) {
        arguments = new Object[args.length - 1];
        System.arraycopy(args, 1, arguments, 0, arguments.length);
    } else {
        arguments = ScriptRuntime.EMPTY_ARRAY;
    }

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, arguments);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, arguments);
    }

    throw new AssertionError("should not reach here");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:NativeFunction.java

示例2: get

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object get(final MethodHandle fallback, final Object jsobj, final Object key)
    throws Throwable {
    if (key instanceof Integer) {
        return ((JSObject)jsobj).getSlot((Integer)key);
    } else if (key instanceof Number) {
        final int index = getIndex((Number)key);
        if (index > -1) {
            return ((JSObject)jsobj).getSlot(index);
        }
    } else if (key instanceof String) {
        final String name = (String)key;
        // get with method name and signature. delegate it to beans linker!
        if (name.indexOf('(') != -1) {
            return fallback.invokeExact(jsobj, key);
        }
        return ((JSObject)jsobj).getMember(name);
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:JSObjectLinker.java

示例3: IN

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
/**
 * ECMA 11.8.6 - The in operator - generic implementation
 *
 * @param property property to check for
 * @param obj object in which to check for property
 *
 * @return true if objects are equal
 */
public static boolean IN(final Object property, final Object obj) {
    final JSType rvalType = JSType.ofNoFunction(obj);

    if (rvalType == JSType.OBJECT) {
        if (obj instanceof ScriptObject) {
            return ((ScriptObject)obj).has(property);
        }

        if (obj instanceof JSObject) {
            return ((JSObject)obj).hasMember(Objects.toString(property));
        }

        return false;
    }

    throw typeError("in.with.non.object", rvalType.toString().toLowerCase(Locale.ENGLISH));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ScriptRuntime.java

示例4: INSTANCEOF

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
/**
 * ECMA 11.8.6 - The strict instanceof operator - generic implementation
 *
 * @param obj first object to compare
 * @param clazz type to check against
 *
 * @return true if {@code obj} is an instanceof {@code clazz}
 */
public static boolean INSTANCEOF(final Object obj, final Object clazz) {
    if (clazz instanceof ScriptFunction) {
        if (obj instanceof ScriptObject) {
            return ((ScriptObject)clazz).isInstance((ScriptObject)obj);
        }
        return false;
    }

    if (clazz instanceof StaticClass) {
        return ((StaticClass)clazz).getRepresentedClass().isInstance(obj);
    }

    if (clazz instanceof JSObject) {
        return ((JSObject)clazz).isInstance(obj);
    }

    // provide for reverse hook
    if (obj instanceof JSObject) {
        return ((JSObject)obj).isInstanceOf(clazz);
    }

    throw typeError("instanceof.on.non.object");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:ScriptRuntime.java

示例5: concatToList

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
private static void concatToList(final ArrayList<Object> list, final Object obj) {
    final boolean isScriptArray  = isArray(obj);
    final boolean isScriptObject = isScriptArray || obj instanceof ScriptObject;
    if (isScriptArray || obj instanceof Iterable || obj instanceof JSObject || (obj != null && obj.getClass().isArray())) {
        final Iterator<Object> iter = arrayLikeIterator(obj, true);
        if (iter.hasNext()) {
            for (int i = 0; iter.hasNext(); ++i) {
                final Object value = iter.next();
                if (value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) {
                    // TODO: eventually rewrite arrayLikeIterator to use a three-state enum for handling
                    // UNDEFINED instead of an "includeUndefined" boolean with states SKIP, INCLUDE,
                    // RETURN_EMPTY. Until then, this is how we'll make sure that empty elements don't make it
                    // into the concatenated array.
                    list.add(ScriptRuntime.EMPTY);
                } else {
                    list.add(value);
                }
            }
        } else if (!isScriptArray) {
            list.add(obj); // add empty object, but not an empty array
        }
    } else {
        // single element, add it
        list.add(obj);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:NativeArray.java

示例6: getGuardedInvocation

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final Object self = request.getReceiver();
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    if (self == null || !canLinkTypeStatic(self.getClass())) {
        return null;
    }

    GuardedInvocation inv;
    if (self instanceof JSObject) {
        inv = lookup(desc, request, linkerServices);
        inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard());
    } else if (self instanceof Map || self instanceof Bindings) {
        // guard to make sure the Map or Bindings does not turn into JSObject later!
        final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
        inv = new GuardedInvocation(beanInv.getInvocation(),
            NashornGuards.combineGuards(beanInv.getGuard(), NashornGuards.getNotJSObjectGuard()));
    } else {
        throw new AssertionError("got instanceof: " + self.getClass()); // Should never reach here.
    }

    return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:JSObjectLinker.java

示例7: get

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object get(final MethodHandle fallback, final Object jsobj, final Object key)
    throws Throwable {
    if (key instanceof Integer) {
        return ((JSObject)jsobj).getSlot((Integer)key);
    } else if (key instanceof Number) {
        final int index = getIndex((Number)key);
        if (index > -1) {
            return ((JSObject)jsobj).getSlot(index);
        } else {
            return ((JSObject)jsobj).getMember(JSType.toString(key));
        }
    } else if (isString(key)) {
        final String name = key.toString();
        // get with method name and signature. delegate it to beans linker!
        if (name.indexOf('(') != -1) {
            return fallback.invokeExact(jsobj, (Object) name);
        }
        return ((JSObject)jsobj).getMember(name);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JSObjectLinker.java

示例8: toValueIterator

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
/**
 * Returns an iterator over property values used in the {@code for each...in} statement. Aside from built-in JS
 * objects, it also operates on Java arrays, any {@link Iterable}, as well as on {@link Map} objects, iterating over
 * map values.
 * @param obj object to iterate on.
 * @return iterator over the object's property values.
 */
public static Iterator<?> toValueIterator(final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).valueIterator();
    }

    if (obj instanceof JSObject) {
        return ((JSObject)obj).values().iterator();
    }

    final Iterator<?> itr = iteratorForJavaArrayOrList(obj);
    if (itr != null) {
        return itr;
    }

    if (obj instanceof Map) {
        return ((Map<?,?>)obj).values().iterator();
    }

    final Object wrapped = Global.instance().wrapAsObject(obj);
    if (wrapped instanceof ScriptObject) {
        return ((ScriptObject)wrapped).valueIterator();
    }

    return Collections.emptyIterator();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:ScriptRuntime.java

示例9: getMember

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@Override
public Object getMember(final String name) {
    switch (name) {
        case "clear":
            return (Runnable)hist::clear;
        case "forEach":
            return (Function<JSObject, Object>)this::iterate;
        case "load":
            return (Consumer<Object>)this::load;
        case "print":
            return (Runnable)this::print;
        case "save":
            return (Consumer<Object>)this::save;
        case "size":
            return hist.size();
        case "toString":
            return (Supplier<String>)this::toString;
    }
    return UNDEFINED;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:HistoryObject.java

示例10: get

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object get(final MethodHandle fallback, final Object jsobj, final Object key)
    throws Throwable {
    if (key instanceof Integer) {
        return ((JSObject)jsobj).getSlot((Integer)key);
    } else if (key instanceof Number) {
        final int index = getIndex((Number)key);
        if (index > -1) {
            return ((JSObject)jsobj).getSlot(index);
        }
    } else if (isString(key)) {
        final String name = key.toString();
        // get with method name and signature. delegate it to beans linker!
        if (name.indexOf('(') != -1) {
            return fallback.invokeExact(jsobj, (Object) name);
        }
        return ((JSObject)jsobj).getMember(name);
    }
    return null;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:21,代码来源:JSObjectLinker.java

示例11: get

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
@Override
@Nullable
public Object get(Object key) {
    IColumn col = this.getColumn((String)key);
    if (col.getDescription().kind == ContentsKind.Date) {
        double dateEncoding = super.getDouble((String)key);
        // https://stackoverflow.com/questions/33110942/supply-javascript-date-to-nashorn-script
        try {
            JSObject object =
                    (JSObject)this.engine.eval("new Date(" + Double.toString(dateEncoding) + ")");
            return object;
        } catch (ScriptException e) {
            throw new RuntimeException(e);
        }
    }

    Object result = super.get(key);
    if (result == null)
        return result;
    return result;
}
 
开发者ID:vmware,项目名称:hillview,代码行数:22,代码来源:JSVirtualRowSnapshot.java

示例12: JsonParser

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
JsonParser() {
  try {
    nashornParser = (JSObject) new ScriptEngineManager().getEngineByName("nashorn").eval("JSON.parse");
  } catch (ScriptException e) {
    throw new IllegalStateException("Can not get 'JSON.parse' from 'nashorn' script engine.", e);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:8,代码来源:JsonParser.java

示例13: hasFunction

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
boolean hasFunction(String funcName) {
    Object member = plugin.get(funcName);
    if (!(member instanceof JSObject)) {
        return false;
    }

    return ((JSObject) member).isFunction();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:9,代码来源:Plugin.java

示例14: apply

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
/**
 * ECMA 15.3.4.3 Function.prototype.apply (thisArg, argArray)
 *
 * @param self   self reference
 * @param thiz   {@code this} arg for apply
 * @param array  array of argument for apply
 * @return result of apply
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object apply(final Object self, final Object thiz, final Object array) {
    checkCallable(self);

    final Object[] args = toApplyArgs(array);

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, args);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, args);
    }
    throw new AssertionError("Should not reach here");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:NativeFunction.java

示例15: getMirrorConverter

import jdk.nashorn.api.scripting.JSObject; //导入依赖的package包/类
private static GuardedInvocation getMirrorConverter(final Class<?> sourceType, final Class<?> targetType) {
    // Could've also used (targetType.isAssignableFrom(ScriptObjectMirror.class) && targetType != Object.class) but
    // it's probably better to explicitly spell out the supported target types
    if (targetType == Map.class || targetType == Bindings.class || targetType == JSObject.class || targetType == ScriptObjectMirror.class) {
        if(ScriptObject.class.isAssignableFrom(sourceType)) {
            return new GuardedInvocation(CREATE_MIRROR);
        }
        return new GuardedInvocation(CREATE_MIRROR, IS_SCRIPT_OBJECT);
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:NashornLinker.java


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