本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject类的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject类的具体用法?Java ScriptObject怎么用?Java ScriptObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptObject类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ScriptObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ECMA 15.2.3.5 Object.create ( O [, Properties] )
*
* @param self self reference
* @param proto prototype object
* @param props properties to define
* @return object created
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject create(final Object self, final Object proto, final Object props) {
if (proto != null) {
Global.checkObject(proto);
}
// FIXME: should we create a proper object with correct number of
// properties?
final ScriptObject newObj = Global.newEmptyInstance();
newObj.setProto((ScriptObject)proto);
if (props != UNDEFINED) {
NativeObject.defineProperties(self, newObj, props);
}
return newObj;
}
示例2: createObject
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
final Object[] objectSpill = new Object[values.size()];
for (final Property property : propertyMap.getProperties()) {
if (!dualFields || property.getType() == Object.class) {
objectSpill[property.getSlot()] = values.get(property.getSlot());
} else {
primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
}
}
final ScriptObject object = dualFields ?
new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
object.setInitialProto(global.getObjectPrototype());
object.setArray(arrayData);
return object;
}
示例3: NativeStrictArguments
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) {
super(proto, map);
setIsArguments();
final ScriptFunction func = Global.instance().getTypeErrorThrower();
// We have to fill user accessor functions late as these are stored
// in this object rather than in the PropertyMap of this object.
final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
initUserAccessors("caller", flags, func, func);
initUserAccessors("callee", flags, func, func);
setArray(ArrayData.allocate(values));
this.length = values.length;
// extend/truncate named arg array as needed and copy values
this.namedArgs = new Object[numParams];
if (numParams > values.length) {
Arrays.fill(namedArgs, UNDEFINED);
}
System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length));
}
示例4: putAll
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
@Override
public void putAll(final Map<? extends String, ? extends Object> map) {
Objects.requireNonNull(map);
final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
inGlobal(new Callable<Object>() {
@Override public Object call() {
for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
final Object value = entry.getValue();
final Object modValue = globalChanged? wrapLikeMe(value, oldGlobal) : value;
final String key = entry.getKey();
checkKey(key);
sobj.set(key, unwrap(modValue, global), getCallSiteFlags());
}
return null;
}
});
}
示例5: toString
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ECMA 15.4.4.2 Array.prototype.toString ( )
*
* @param self self reference
* @return string representation of array
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toString(final Object self) {
final Object obj = Global.toObject(self);
if (obj instanceof ScriptObject) {
final InvokeByName joinInvoker = getJOIN();
final ScriptObject sobj = (ScriptObject)obj;
try {
final Object join = joinInvoker.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(join)) {
return joinInvoker.getInvoker().invokeExact(join, sobj);
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
// FIXME: should lookup Object.prototype.toString and call that?
return ScriptRuntime.builtinObjectToString(self);
}
示例6: set__proto__
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object set__proto__(final Object self, final Object proto) {
// See ES6 draft spec: B.2.2.1.2 set Object.prototype.__proto__
// Step 1
Global.checkObjectCoercible(self);
// Step 4
if (! (self instanceof ScriptObject)) {
return UNDEFINED;
}
final ScriptObject sobj = (ScriptObject)self;
// __proto__ assignment ignores non-nulls and non-objects
// step 3: If Type(proto) is neither Object nor Null, then return undefined.
if (proto == null || proto instanceof ScriptObject) {
sobj.setPrototypeOf(proto);
}
return UNDEFINED;
}
示例7: isPrototypeOf
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ECMA 15.2.4.6 Object.prototype.isPrototypeOf (V)
*
* @param self self reference
* @param v v prototype object to check against
* @return true if object is prototype of v
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean isPrototypeOf(final Object self, final Object v) {
if (!(v instanceof ScriptObject)) {
return false;
}
final Object obj = Global.toObject(self);
ScriptObject proto = (ScriptObject)v;
do {
proto = proto.getProto();
if (proto == obj) {
return true;
}
} while (proto != null);
return false;
}
示例8: extractBuiltinProperties
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
private List<jdk.nashorn.internal.runtime.Property> extractBuiltinProperties(final String name, final ScriptObject func) {
final List<jdk.nashorn.internal.runtime.Property> list = new ArrayList<>();
list.addAll(Arrays.asList(func.getMap().getProperties()));
if (func instanceof ScriptFunction) {
final ScriptObject proto = ScriptFunction.getPrototype((ScriptFunction)func);
if (proto != null) {
list.addAll(Arrays.asList(proto.getMap().getProperties()));
}
}
final jdk.nashorn.internal.runtime.Property prop = getProperty(name);
if (prop != null) {
list.add(prop);
}
return list;
}
示例9: setPrototypeOf
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* Nashorn extension: Object.setPrototypeOf ( O, proto )
* Also found in ES6 draft specification.
*
* @param self self reference
* @param obj object to set prototype for
* @param proto prototype object to be used
* @return object whose prototype is set
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object setPrototypeOf(final Object self, final Object obj, final Object proto) {
if (obj instanceof ScriptObject) {
((ScriptObject)obj).setPrototypeOf(proto);
return obj;
} else if (obj instanceof ScriptObjectMirror) {
((ScriptObjectMirror)obj).setProto(proto);
return obj;
}
throw notAnObject(obj);
}
示例10: putAll
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
@Override
public void putAll(final Map<? extends String, ? extends Object> map) {
final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
inGlobal(new Callable<Object>() {
@Override public Object call() {
for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
final Object value = entry.getValue();
final Object modValue = globalChanged? wrap(value, oldGlobal) : value;
sobj.set(entry.getKey(), unwrap(modValue, global), getCallSiteFlags());
}
return null;
}
});
}
示例11: wrap
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* Make a script object mirror on given object if needed. Also converts ConsString instances to Strings.
*
* @param obj object to be wrapped/converted
* @param homeGlobal global to which this object belongs. Not used for ConsStrings.
* @return wrapped/converted object
*/
public static Object wrap(final Object obj, final Object homeGlobal) {
if(obj instanceof ScriptObject) {
return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj;
}
if(obj instanceof ConsString) {
return obj.toString();
}
return obj;
}
示例12: slice
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ECMA 15.4.4.10 Array.prototype.slice ( start [ , end ] )
*
* @param self self reference
* @param start start of slice (inclusive)
* @param end end of slice (optional, exclusive)
* @return sliced array
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object slice(final Object self, final Object start, final Object end) {
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());
final long relativeStart = JSType.toLong(start);
final long relativeEnd = end == ScriptRuntime.UNDEFINED ? len : JSType.toLong(end);
long k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long finale = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
if (k >= finale) {
return new NativeArray(0);
}
if (bulkable(sobj)) {
return new NativeArray(sobj.getArray().slice(k, finale));
}
// Construct array with proper length to have a deleted filter on undefined elements
final NativeArray copy = new NativeArray(finale - k);
for (long n = 0; k < finale; n++, k++) {
if (sobj.has(k)) {
copy.defineOwnProperty(ArrayIndex.getArrayIndex(n), sobj.get(k));
}
}
return copy;
}
示例13: reverseArrayLikeIterator
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ArrayLikeIterator factory (reverse order)
* @param object object over which to do reverse element iteration
* @param includeUndefined should undefined elements be included in the iteration
* @return iterator
*/
public static ArrayLikeIterator<Object> reverseArrayLikeIterator(final Object object, final boolean includeUndefined) {
Object obj = object;
if (ScriptObject.isArray(obj)) {
return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined);
}
obj = JSType.toScriptObject(obj);
if (obj instanceof ScriptObject) {
return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined);
}
if (obj instanceof JSObject) {
return new ReverseJSObjectIterator((JSObject)obj, includeUndefined);
}
if (obj instanceof List) {
return new ReverseJavaListIterator((List<?>)obj, includeUndefined);
}
if (obj != null && obj.getClass().isArray()) {
return new ReverseJavaArrayIterator(obj, includeUndefined);
}
return new EmptyArrayLikeIterator();
}
示例14: match
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* ECMA 15.5.4.10 String.prototype.match (regexp)
* @param self self reference
* @param regexp regexp expression
* @return array of regexp matches
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject match(final Object self, final Object regexp) {
final String str = checkObjectToString(self);
NativeRegExp nativeRegExp;
if (regexp == UNDEFINED) {
nativeRegExp = new NativeRegExp("");
} else {
nativeRegExp = Global.toRegExp(regexp);
}
if (!nativeRegExp.getGlobal()) {
return nativeRegExp.exec(str);
}
nativeRegExp.setLastIndex(0);
int previousLastIndex = 0;
final List<Object> matches = new ArrayList<>();
Object result;
while ((result = nativeRegExp.exec(str)) != null) {
final int thisIndex = nativeRegExp.getLastIndex();
if (thisIndex == previousLastIndex) {
nativeRegExp.setLastIndex(thisIndex + 1);
previousLastIndex = thisIndex + 1;
} else {
previousLastIndex = thisIndex;
}
matches.add(((ScriptObject)result).get(0));
}
if (matches.isEmpty()) {
return null;
}
return new NativeArray(matches.toArray());
}
示例15: initEcmaError
import jdk.nashorn.internal.runtime.ScriptObject; //导入依赖的package包/类
/**
* Initialization function for ECMA errors. Stores the error
* in the ecmaError field of this class. It is only initialized
* once, and then reused
*
* @param global the global
* @return initialized exception
*/
protected NashornException initEcmaError(final ScriptObject global) {
if (ecmaError != null) {
return this; // initialized already!
}
final Object thrown = getThrown();
if (thrown instanceof ScriptObject) {
setEcmaError(ScriptObjectMirror.wrap(thrown, global));
} else {
setEcmaError(thrown);
}
return this;
}