本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject.defineOwnProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject.defineOwnProperty方法的具体用法?Java ScriptObject.defineOwnProperty怎么用?Java ScriptObject.defineOwnProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptObject
的用法示例。
在下文中一共展示了ScriptObject.defineOwnProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defineProperties
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 5.2.3.7 Object.defineProperties ( O, Properties )
*
* @param self self reference
* @param obj object in which to define properties
* @param props properties
* @return object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject defineProperties(final Object self, final Object obj, final Object props) {
final ScriptObject sobj = Global.checkObject(obj);
final Object propsObj = Global.toObject(props);
if (propsObj instanceof ScriptObject) {
final Object[] keys = ((ScriptObject)propsObj).getOwnKeys(false);
for (final Object key : keys) {
final String prop = JSType.toString(key);
sobj.defineOwnProperty(prop, ((ScriptObject)propsObj).get(prop), true);
}
}
return sobj;
}
示例2: splice
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param args arguments
* @return result of splice
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
final Object obj = Global.toObject(self);
if (!(obj instanceof ScriptObject)) {
return ScriptRuntime.UNDEFINED;
}
final Object start = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
final Object deleteCount = args.length > 1 ? args[1] : ScriptRuntime.UNDEFINED;
Object[] items;
if (args.length > 2) {
items = new Object[args.length - 2];
System.arraycopy(args, 2, items, 0, items.length);
} else {
items = ScriptRuntime.EMPTY_ARRAY;
}
final ScriptObject sobj = (ScriptObject)obj;
final long len = JSType.toUint32(sobj.getLength());
final long relativeStart = JSType.toLong(start);
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);
NativeArray returnValue;
if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
try {
returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));
// Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
int k = (int) actualStart;
for (int i = 0; i < items.length; i++, k++) {
sobj.defineOwnProperty(k, items[i]);
}
} catch (final UnsupportedOperationException uoe) {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
} else {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
return returnValue;
}
示例3: splice
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param args arguments
* @return result of splice
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
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(args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED);
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount;
Object[] items = ScriptRuntime.EMPTY_ARRAY;
if (args.length == 0) {
actualDeleteCount = 0;
} else if (args.length == 1) {
actualDeleteCount = len - actualStart;
} else {
actualDeleteCount = Math.min(Math.max(JSType.toLong(args[1]), 0), len - actualStart);
if (args.length > 2) {
items = new Object[args.length - 2];
System.arraycopy(args, 2, items, 0, items.length);
}
}
NativeArray returnValue;
if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
try {
returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));
// Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
int k = (int) actualStart;
for (int i = 0; i < items.length; i++, k++) {
sobj.defineOwnProperty(k, items[i]);
}
} catch (final UnsupportedOperationException uoe) {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
} else {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
return returnValue;
}
示例4: defineProperty
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.2.3.6 Object.defineProperty ( O, P, Attributes )
*
* @param self self reference
* @param obj object in which to define a property
* @param prop property to define
* @param attr attributes for property descriptor
* @return object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject defineProperty(final Object self, final Object obj, final Object prop, final Object attr) {
final ScriptObject sobj = Global.checkObject(obj);
sobj.defineOwnProperty(JSType.toString(prop), attr, true);
return sobj;
}
示例5: defineProperty
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.2.3.6 Object.defineProperty ( O, P, Attributes )
*
* @param self self reference
* @param obj object in which to define a property
* @param prop property to define
* @param attr attributes for property descriptor
* @return object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject defineProperty(final Object self, final Object obj, final Object prop, final Object attr) {
final ScriptObject sobj = Global.checkObject(obj);
sobj.defineOwnProperty(JSType.toPropertyKey(prop), attr, true);
return sobj;
}