本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject.put方法的具体用法?Java ScriptObject.put怎么用?Java ScriptObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptObject
的用法示例。
在下文中一共展示了ScriptObject.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStack
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension: Error.prototype.stack
* "stack" property is a string typed value containing JavaScript stack frames.
* Each frame information is separated bv "\n" character.
*
* @param self self reference
*
* @return value of "stack" property
*/
public static Object getStack(final Object self) {
final ScriptObject sobj = Global.checkObject(self);
if (sobj.has(STACK)) {
return sobj.get(STACK);
}
final Object exception = ECMAException.getException(sobj);
if (exception instanceof Throwable) {
final Object value = getScriptStackString(sobj, (Throwable)exception);
if (sobj.hasOwnProperty(STACK)) {
sobj.put(STACK, value, false);
} else {
sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value);
}
return value;
}
return UNDEFINED;
}
示例2: setLineNumber
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension: Error.prototype.lineNumber
*
* @param self self reference
* @param value value of line number
*
* @return value that was set
*/
public static Object setLineNumber(final Object self, final Object value) {
final ScriptObject sobj = Global.checkObject(self);
if (sobj.hasOwnProperty(LINENUMBER)) {
sobj.put(LINENUMBER, value, false);
} else {
sobj.addOwnProperty(LINENUMBER, Attribute.NOT_ENUMERABLE, value);
}
return value;
}
示例3: setColumnNumber
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension: Error.prototype.columnNumber
*
* @param self self reference
* @param value value of column number
*
* @return value that was set
*/
public static Object setColumnNumber(final Object self, final Object value) {
final ScriptObject sobj = Global.checkObject(self);
if (sobj.hasOwnProperty(COLUMNNUMBER)) {
sobj.put(COLUMNNUMBER, value, false);
} else {
sobj.addOwnProperty(COLUMNNUMBER, Attribute.NOT_ENUMERABLE, value);
}
return value;
}
示例4: setFileName
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension: Error.prototype.fileName
*
* @param self self reference
* @param value value of file name
*
* @return value that was set
*/
public static Object setFileName(final Object self, final Object value) {
final ScriptObject sobj = Global.checkObject(self);
if (sobj.hasOwnProperty(FILENAME)) {
sobj.put(FILENAME, value, false);
} else {
sobj.addOwnProperty(FILENAME, Attribute.NOT_ENUMERABLE, value);
}
return value;
}
示例5: setStack
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension
* Accessed from {@link Global} while setting up the Error.prototype
*
* @param self self reference
* @param value value to set "stack" property to, must be {@code ScriptObject}
*
* @return value that was set
*/
public static Object setStack(final Object self, final Object value) {
final ScriptObject sobj = Global.checkObject(self);
if (sobj.hasOwnProperty(STACK)) {
sobj.put(STACK, value, false);
} else {
sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value);
}
return value;
}
示例6: reflectionTest
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
@Test
public void reflectionTest() {
final Options options = new Options("");
final ErrorManager errors = new ErrorManager();
final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
final boolean strict = cx.getEnv()._strict;
final Global oldGlobal = Context.getGlobal();
Context.setGlobal(cx.createGlobal());
try {
final String code = "var obj = { x: 344, y: 42 }";
eval(cx, "<reflectionTest>", code);
final Object obj = Context.getGlobal().get("obj");
assertTrue(obj instanceof ScriptObject);
final ScriptObject sobj = (ScriptObject)obj;
int count = 0;
for (final Map.Entry<?, ?> ex : sobj.entrySet()) {
final Object key = ex.getKey();
if (key.equals("x")) {
assertTrue(ex.getValue() instanceof Number);
assertTrue(344.0 == ((Number)ex.getValue()).doubleValue());
count++;
} else if (key.equals("y")) {
assertTrue(ex.getValue() instanceof Number);
assertTrue(42.0 == ((Number)ex.getValue()).doubleValue());
count++;
}
}
assertEquals(count, 2);
assertEquals(sobj.size(), 2);
// add property
sobj.put("zee", "hello", strict);
assertEquals(sobj.get("zee"), "hello");
assertEquals(sobj.size(), 3);
} finally {
Context.setGlobal(oldGlobal);
}
}