提交 44dc1762 编写于 作者: S sundar

Merge

/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.nashorn.api.scripting;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
/**
* This is the base class for nashorn ScriptObjectMirror class.
*
* This class can also be subclassed by an arbitrary Java class. Nashorn will
* treat objects of such classes just like nashorn script objects. Usual nashorn
* operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
* to appropriate method call of this class.
*/
public abstract class AbstractJSObject implements JSObject {
/**
* Call this object as a JavaScript function. This is equivalent to
* 'func.apply(thiz, args)' in JavaScript.
*
* @param thiz 'this' object to be passed to the function
* @param args arguments to method
* @return result of call
*/
@Override
public Object call(final Object thiz, final Object... args) {
throw new UnsupportedOperationException("call");
}
/**
* Call this 'constructor' JavaScript function to create a new object.
* This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
*
* @param args arguments to method
* @return result of constructor call
*/
@Override
public Object newObject(final Object... args) {
throw new UnsupportedOperationException("newObject");
}
/**
* Evaluate a JavaScript expression.
*
* @param s JavaScript expression to evaluate
* @return evaluation result
*/
@Override
public Object eval(final String s) {
throw new UnsupportedOperationException("eval");
}
/**
* Retrieves a named member of this JavaScript object.
*
* @param name of member
* @return member
*/
@Override
public Object getMember(final String name) {
return null;
}
/**
* Retrieves an indexed member of this JavaScript object.
*
* @param index index slot to retrieve
* @return member
*/
@Override
public Object getSlot(final int index) {
return null;
}
/**
* Does this object have a named member?
*
* @param name name of member
* @return true if this object has a member of the given name
*/
@Override
public boolean hasMember(final String name) {
return false;
}
/**
* Does this object have a indexed property?
*
* @param slot index to check
* @return true if this object has a slot
*/
@Override
public boolean hasSlot(final int slot) {
return false;
}
/**
* Remove a named member from this JavaScript object
*
* @param name name of the member
*/
@Override
public void removeMember(final String name) {
//empty
}
/**
* Set a named member in this JavaScript object
*
* @param name name of the member
* @param value value of the member
*/
@Override
public void setMember(final String name, final Object value) {
//empty
}
/**
* Set an indexed member in this JavaScript object
*
* @param index index of the member slot
* @param value value of the member
*/
@Override
public void setSlot(final int index, final Object value) {
//empty
}
// property and value iteration
/**
* Returns the set of all property names of this object.
*
* @return set of property names
*/
@Override
@SuppressWarnings("unchecked")
public Set<String> keySet() {
return Collections.EMPTY_SET;
}
/**
* Returns the set of all property values of this object.
*
* @return set of property values.
*/
@Override
@SuppressWarnings("unchecked")
public Collection<Object> values() {
return Collections.EMPTY_SET;
}
// JavaScript instanceof check
/**
* Checking whether the given object is an instance of 'this' object.
*
* @param instance instace to check
* @return true if the given 'instance' is an instance of this 'function' object
*/
@Override
public boolean isInstance(final Object instance) {
return false;
}
/**
* Checking whether this object is an instance of the given 'clazz' object.
*
* @param clazz clazz to check
* @return true if this object is an instance of the given 'clazz'
*/
@Override
public boolean isInstanceOf(final Object clazz) {
if (clazz instanceof JSObject) {
return ((JSObject)clazz).isInstance(this);
}
return false;
}
/**
* ECMA [[Class]] property
*
* @return ECMA [[Class]] property value of this object
*/
@Override
public String getClassName() {
return getClass().getName();
}
/**
* Is this a function object?
*
* @return if this mirror wraps a ECMAScript function instance
*/
@Override
public boolean isFunction() {
return false;
}
/**
* Is this a 'use strict' function object?
*
* @return true if this mirror represents a ECMAScript 'use strict' function
*/
@Override
public boolean isStrictFunction() {
return false;
}
/**
* Is this an array object?
*
* @return if this mirror wraps a ECMAScript array object
*/
@Override
public boolean isArray() {
return false;
}
/**
* Returns this object's numeric value.
*
* @return this object's numeric value.
*/
@Override
public double toNumber() {
return Double.NaN;
}
}
...@@ -30,14 +30,12 @@ import java.util.Collections; ...@@ -30,14 +30,12 @@ import java.util.Collections;
import java.util.Set; import java.util.Set;
/** /**
* This is the base class for nashorn ScriptObjectMirror class. * This interface can be implemented by an arbitrary Java class. Nashorn will
*
* This class can also be subclassed by an arbitrary Java class. Nashorn will
* treat objects of such classes just like nashorn script objects. Usual nashorn * treat objects of such classes just like nashorn script objects. Usual nashorn
* operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
* to appropriate method call of this class. * to appropriate method call of this interface.
*/ */
public abstract class JSObject { public interface JSObject {
/** /**
* Call this object as a JavaScript function. This is equivalent to * Call this object as a JavaScript function. This is equivalent to
* 'func.apply(thiz, args)' in JavaScript. * 'func.apply(thiz, args)' in JavaScript.
...@@ -46,9 +44,7 @@ public abstract class JSObject { ...@@ -46,9 +44,7 @@ public abstract class JSObject {
* @param args arguments to method * @param args arguments to method
* @return result of call * @return result of call
*/ */
public Object call(final Object thiz, final Object... args) { public Object call(final Object thiz, final Object... args);
throw new UnsupportedOperationException("call");
}
/** /**
* Call this 'constructor' JavaScript function to create a new object. * Call this 'constructor' JavaScript function to create a new object.
...@@ -57,9 +53,7 @@ public abstract class JSObject { ...@@ -57,9 +53,7 @@ public abstract class JSObject {
* @param args arguments to method * @param args arguments to method
* @return result of constructor call * @return result of constructor call
*/ */
public Object newObject(final Object... args) { public Object newObject(final Object... args);
throw new UnsupportedOperationException("newObject");
}
/** /**
* Evaluate a JavaScript expression. * Evaluate a JavaScript expression.
...@@ -67,20 +61,7 @@ public abstract class JSObject { ...@@ -67,20 +61,7 @@ public abstract class JSObject {
* @param s JavaScript expression to evaluate * @param s JavaScript expression to evaluate
* @return evaluation result * @return evaluation result
*/ */
public Object eval(final String s) { public Object eval(final String s);
throw new UnsupportedOperationException("eval");
}
/**
* Call a JavaScript function member of this object.
*
* @param name name of the member function to call
* @param args arguments to be passed to the member function
* @return result of call
*/
public Object callMember(final String name, final Object... args) {
throw new UnsupportedOperationException("call");
}
/** /**
* Retrieves a named member of this JavaScript object. * Retrieves a named member of this JavaScript object.
...@@ -88,9 +69,7 @@ public abstract class JSObject { ...@@ -88,9 +69,7 @@ public abstract class JSObject {
* @param name of member * @param name of member
* @return member * @return member
*/ */
public Object getMember(final String name) { public Object getMember(final String name);
return null;
}
/** /**
* Retrieves an indexed member of this JavaScript object. * Retrieves an indexed member of this JavaScript object.
...@@ -98,9 +77,7 @@ public abstract class JSObject { ...@@ -98,9 +77,7 @@ public abstract class JSObject {
* @param index index slot to retrieve * @param index index slot to retrieve
* @return member * @return member
*/ */
public Object getSlot(final int index) { public Object getSlot(final int index);
return null;
}
/** /**
* Does this object have a named member? * Does this object have a named member?
...@@ -108,9 +85,7 @@ public abstract class JSObject { ...@@ -108,9 +85,7 @@ public abstract class JSObject {
* @param name name of member * @param name name of member
* @return true if this object has a member of the given name * @return true if this object has a member of the given name
*/ */
public boolean hasMember(final String name) { public boolean hasMember(final String name);
return false;
}
/** /**
* Does this object have a indexed property? * Does this object have a indexed property?
...@@ -118,18 +93,14 @@ public abstract class JSObject { ...@@ -118,18 +93,14 @@ public abstract class JSObject {
* @param slot index to check * @param slot index to check
* @return true if this object has a slot * @return true if this object has a slot
*/ */
public boolean hasSlot(final int slot) { public boolean hasSlot(final int slot);
return false;
}
/** /**
* Remove a named member from this JavaScript object * Remove a named member from this JavaScript object
* *
* @param name name of the member * @param name name of the member
*/ */
public void removeMember(final String name) { public void removeMember(final String name);
//empty
}
/** /**
* Set a named member in this JavaScript object * Set a named member in this JavaScript object
...@@ -137,9 +108,7 @@ public abstract class JSObject { ...@@ -137,9 +108,7 @@ public abstract class JSObject {
* @param name name of the member * @param name name of the member
* @param value value of the member * @param value value of the member
*/ */
public void setMember(final String name, final Object value) { public void setMember(final String name, final Object value);
//empty
}
/** /**
* Set an indexed member in this JavaScript object * Set an indexed member in this JavaScript object
...@@ -147,9 +116,7 @@ public abstract class JSObject { ...@@ -147,9 +116,7 @@ public abstract class JSObject {
* @param index index of the member slot * @param index index of the member slot
* @param value value of the member * @param value value of the member
*/ */
public void setSlot(final int index, final Object value) { public void setSlot(final int index, final Object value);
//empty
}
// property and value iteration // property and value iteration
...@@ -158,20 +125,14 @@ public abstract class JSObject { ...@@ -158,20 +125,14 @@ public abstract class JSObject {
* *
* @return set of property names * @return set of property names
*/ */
@SuppressWarnings("unchecked") public Set<String> keySet();
public Set<String> keySet() {
return Collections.EMPTY_SET;
}
/** /**
* Returns the set of all property values of this object. * Returns the set of all property values of this object.
* *
* @return set of property values. * @return set of property values.
*/ */
@SuppressWarnings("unchecked") public Collection<Object> values();
public Collection<Object> values() {
return Collections.EMPTY_SET;
}
// JavaScript instanceof check // JavaScript instanceof check
...@@ -181,9 +142,7 @@ public abstract class JSObject { ...@@ -181,9 +142,7 @@ public abstract class JSObject {
* @param instance instace to check * @param instance instace to check
* @return true if the given 'instance' is an instance of this 'function' object * @return true if the given 'instance' is an instance of this 'function' object
*/ */
public boolean isInstance(final Object instance) { public boolean isInstance(final Object instance);
return false;
}
/** /**
* Checking whether this object is an instance of the given 'clazz' object. * Checking whether this object is an instance of the given 'clazz' object.
...@@ -191,56 +150,40 @@ public abstract class JSObject { ...@@ -191,56 +150,40 @@ public abstract class JSObject {
* @param clazz clazz to check * @param clazz clazz to check
* @return true if this object is an instance of the given 'clazz' * @return true if this object is an instance of the given 'clazz'
*/ */
public boolean isInstanceOf(final Object clazz) { public boolean isInstanceOf(final Object clazz);
if (clazz instanceof JSObject) {
return ((JSObject)clazz).isInstance(this);
}
return false;
}
/** /**
* ECMA [[Class]] property * ECMA [[Class]] property
* *
* @return ECMA [[Class]] property value of this object * @return ECMA [[Class]] property value of this object
*/ */
public String getClassName() { public String getClassName();
return getClass().getName();
}
/** /**
* Is this a function object? * Is this a function object?
* *
* @return if this mirror wraps a ECMAScript function instance * @return if this mirror wraps a ECMAScript function instance
*/ */
public boolean isFunction() { public boolean isFunction();
return false;
}
/** /**
* Is this a 'use strict' function object? * Is this a 'use strict' function object?
* *
* @return true if this mirror represents a ECMAScript 'use strict' function * @return true if this mirror represents a ECMAScript 'use strict' function
*/ */
public boolean isStrictFunction() { public boolean isStrictFunction();
return false;
}
/** /**
* Is this an array object? * Is this an array object?
* *
* @return if this mirror wraps a ECMAScript array object * @return if this mirror wraps a ECMAScript array object
*/ */
public boolean isArray() { public boolean isArray();
return false;
}
/** /**
* Returns this object's numeric value. * Returns this object's numeric value.
* *
* @return this object's numeric value. * @return this object's numeric value.
*/ */
public double toNumber() { public double toNumber();
return Double.NaN;
}
} }
...@@ -51,7 +51,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime; ...@@ -51,7 +51,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
/** /**
* Mirror object that wraps a given Nashorn Script object. * Mirror object that wraps a given Nashorn Script object.
*/ */
public final class ScriptObjectMirror extends JSObject implements Bindings { public final class ScriptObjectMirror extends AbstractJSObject implements Bindings {
private static AccessControlContext getContextAccCtxt() { private static AccessControlContext getContextAccCtxt() {
final Permissions perms = new Permissions(); final Permissions perms = new Permissions();
perms.add(new RuntimePermission(Context.NASHORN_GET_CONTEXT)); perms.add(new RuntimePermission(Context.NASHORN_GET_CONTEXT));
...@@ -162,7 +162,6 @@ public final class ScriptObjectMirror extends JSObject implements Bindings { ...@@ -162,7 +162,6 @@ public final class ScriptObjectMirror extends JSObject implements Bindings {
}); });
} }
@Override
public Object callMember(final String functionName, final Object... args) { public Object callMember(final String functionName, final Object... args) {
functionName.getClass(); // null check functionName.getClass(); // null check
final ScriptObject oldGlobal = Context.getGlobal(); final ScriptObject oldGlobal = Context.getGlobal();
......
...@@ -1043,6 +1043,10 @@ public enum JSType { ...@@ -1043,6 +1043,10 @@ public enum JSType {
return toNumber((ScriptObject)obj); return toNumber((ScriptObject)obj);
} }
if (obj instanceof JSObject) {
return ((JSObject)obj).toNumber();
}
return Double.NaN; return Double.NaN;
} }
......
...@@ -33,6 +33,7 @@ import java.util.NoSuchElementException; ...@@ -33,6 +33,7 @@ import java.util.NoSuchElementException;
import java.util.RandomAccess; import java.util.RandomAccess;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.api.scripting.JSObject;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.runtime.linker.Bootstrap; import jdk.nashorn.internal.runtime.linker.Bootstrap;
import jdk.nashorn.internal.runtime.linker.InvokeByName; import jdk.nashorn.internal.runtime.linker.InvokeByName;
...@@ -135,7 +136,8 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random ...@@ -135,7 +136,8 @@ public abstract class ListAdapter extends AbstractList<Object> implements Random
*/ */
public static ListAdapter create(final Object obj) { public static ListAdapter create(final Object obj) {
if (obj instanceof ScriptObject) { if (obj instanceof ScriptObject) {
return new ScriptObjectListAdapter((ScriptObject)obj); final Object mirror = ScriptObjectMirror.wrap(obj, Context.getGlobal());
return new JSObjectListAdapter((JSObject)mirror);
} else if (obj instanceof JSObject) { } else if (obj instanceof JSObject) {
return new JSObjectListAdapter((JSObject)obj); return new JSObjectListAdapter((JSObject)obj);
} else { } else {
......
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.nashorn.internal.runtime;
/**
* A ListAdapter that can wrap a ScriptObject.
*/
public final class ScriptObjectListAdapter extends ListAdapter {
/**
* Creates a new list wrapper for the specified ScriptObject.
* @param obj script the object to wrap
*/
public ScriptObjectListAdapter(final ScriptObject obj) {
super(obj);
}
@Override
public int size() {
return JSType.toInt32(((ScriptObject)obj).getLength());
}
@Override
protected Object getAt(int index) {
return ((ScriptObject)obj).get(index);
}
@Override
protected void setAt(int index, Object element) {
((ScriptObject)obj).set(index, element, false);
}
}
...@@ -107,8 +107,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy ...@@ -107,8 +107,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy
return c > 2 ? findSetMethod(desc) : findSetIndexMethod(); return c > 2 ? findSetMethod(desc) : findSetIndexMethod();
case "call": case "call":
return findCallMethod(desc); return findCallMethod(desc);
case "callMethod":
return findCallMethodMethod(desc);
case "new": case "new":
return findNewMethod(desc); return findNewMethod(desc);
default: default:
...@@ -134,13 +132,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy ...@@ -134,13 +132,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy
return new GuardedInvocation(JSOBJECTLINKER_PUT, null, IS_JSOBJECT_GUARD); return new GuardedInvocation(JSOBJECTLINKER_PUT, null, IS_JSOBJECT_GUARD);
} }
private static GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc) {
final String methodName = desc.getNameToken(2);
MethodHandle func = MH.insertArguments(JSOBJECT_CALLMEMBER, 1, methodName);
func = MH.asCollector(func, Object[].class, desc.getMethodType().parameterCount() - 1);
return new GuardedInvocation(func, null, IS_JSOBJECT_GUARD);
}
private static GuardedInvocation findCallMethod(final CallSiteDescriptor desc) { private static GuardedInvocation findCallMethod(final CallSiteDescriptor desc) {
final MethodHandle func = MH.asCollector(JSOBJECT_CALL, Object[].class, desc.getMethodType().parameterCount() - 2); final MethodHandle func = MH.asCollector(JSOBJECT_CALL, Object[].class, desc.getMethodType().parameterCount() - 2);
return new GuardedInvocation(func, null, IS_JSOBJECT_GUARD); return new GuardedInvocation(func, null, IS_JSOBJECT_GUARD);
...@@ -216,7 +207,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy ...@@ -216,7 +207,6 @@ final class JSObjectLinker implements TypeBasedGuardingDynamicLinker, GuardingTy
// method handles of JSObject class // method handles of JSObject class
private static final MethodHandle JSOBJECT_GETMEMBER = findJSObjectMH("getMember", Object.class, String.class); private static final MethodHandle JSOBJECT_GETMEMBER = findJSObjectMH("getMember", Object.class, String.class);
private static final MethodHandle JSOBJECT_SETMEMBER = findJSObjectMH("setMember", Void.TYPE, String.class, Object.class); private static final MethodHandle JSOBJECT_SETMEMBER = findJSObjectMH("setMember", Void.TYPE, String.class, Object.class);
private static final MethodHandle JSOBJECT_CALLMEMBER = findJSObjectMH("callMember", Object.class, String.class, Object[].class);
private static final MethodHandle JSOBJECT_CALL = findJSObjectMH("call", Object.class, Object.class, Object[].class); private static final MethodHandle JSOBJECT_CALL = findJSObjectMH("call", Object.class, Object.class, Object[].class);
private static final MethodHandle JSOBJECT_NEW = findJSObjectMH("newObject", Object.class, Object[].class); private static final MethodHandle JSOBJECT_NEW = findJSObjectMH("newObject", Object.class, Object[].class);
......
...@@ -100,3 +100,9 @@ var obj = new JSObject() { ...@@ -100,3 +100,9 @@ var obj = new JSObject() {
var jlist = Java.to(obj, java.util.List); var jlist = Java.to(obj, java.util.List);
print(jlist instanceof java.util.List); print(jlist instanceof java.util.List);
print(jlist); print(jlist);
var obj = new JSObject() {
toNumber: function() { return 42; }
};
print(32 + obj);
...@@ -10,3 +10,4 @@ true ...@@ -10,3 +10,4 @@ true
[hello, world] [hello, world]
true true
[nashorn, js] [nashorn, js]
74
...@@ -46,7 +46,7 @@ import org.testng.annotations.Test; ...@@ -46,7 +46,7 @@ import org.testng.annotations.Test;
* JSObject implementations. * JSObject implementations.
*/ */
public class PluggableJSObjectTest { public class PluggableJSObjectTest {
public static class MapWrapperObject extends JSObject { public static class MapWrapperObject extends AbstractJSObject {
private final HashMap<String, Object> map = new LinkedHashMap<>(); private final HashMap<String, Object> map = new LinkedHashMap<>();
public HashMap<String, Object> getMap() { public HashMap<String, Object> getMap() {
...@@ -109,7 +109,7 @@ public class PluggableJSObjectTest { ...@@ -109,7 +109,7 @@ public class PluggableJSObjectTest {
} }
} }
public static class BufferObject extends JSObject { public static class BufferObject extends AbstractJSObject {
private final IntBuffer buf; private final IntBuffer buf;
public BufferObject(int size) { public BufferObject(int size) {
...@@ -170,7 +170,7 @@ public class PluggableJSObjectTest { ...@@ -170,7 +170,7 @@ public class PluggableJSObjectTest {
} }
} }
public static class Adder extends JSObject { public static class Adder extends AbstractJSObject {
@Override @Override
public Object call(Object thiz, Object... args) { public Object call(Object thiz, Object... args) {
double res = 0.0; double res = 0.0;
...@@ -202,7 +202,7 @@ public class PluggableJSObjectTest { ...@@ -202,7 +202,7 @@ public class PluggableJSObjectTest {
} }
} }
public static class Factory extends JSObject { public static class Factory extends AbstractJSObject {
@Override @Override
public Object newObject(Object... args) { public Object newObject(Object... args) {
return new HashMap<Object, Object>(); return new HashMap<Object, Object>();
......
...@@ -129,7 +129,7 @@ public class ScriptObjectMirrorTest { ...@@ -129,7 +129,7 @@ public class ScriptObjectMirrorTest {
final ScriptEngine e = m.getEngineByName("nashorn"); final ScriptEngine e = m.getEngineByName("nashorn");
try { try {
e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }");
JSObject obj = (JSObject) e.get("obj"); ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj");
// try basic get on existing properties // try basic get on existing properties
if (!obj.getMember("bar").equals("hello")) { if (!obj.getMember("bar").equals("hello")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册