jdk.nashorn.api.scripting.JSObject Java Examples

The following examples show how to use jdk.nashorn.api.scripting.JSObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSObjectLinker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: NativeFunction.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
    if (!(self instanceof ScriptFunction) && !(self instanceof JSObject)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(self));
    }

    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");
}
 
Example #3
Source File: NativeFunction.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
}
 
Example #4
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #5
Source File: JSObjectLinker.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context
    final Object self = requestWithoutContext.getReceiver();
    final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();

    if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) {
        // We only support standard "dyn:*[:*]" operations
        return null;
    }

    final GuardedInvocation inv;
    if (self instanceof JSObject) {
        inv = lookup(desc);
    } else {
        throw new AssertionError(); // Should never reach here.
    }

    return Bootstrap.asType(inv, linkerServices, desc);
}
 
Example #6
Source File: ScriptRuntime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.of(obj);

    if (rvalType == JSType.OBJECT || rvalType == JSType.FUNCTION) {
        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));
}
 
Example #7
Source File: ScriptRuntime.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.of(obj);

    if (rvalType == JSType.OBJECT || rvalType == JSType.FUNCTION) {
        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));
}
 
Example #8
Source File: JSObjectLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #9
Source File: JSObjectLinker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #10
Source File: ScriptRuntime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
}
 
Example #11
Source File: ScriptRuntime.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
}
 
Example #12
Source File: NashornLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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);
        } else if (sourceType.isAssignableFrom(ScriptObject.class) || sourceType.isInterface()) {
            return new GuardedInvocation(CREATE_MIRROR, IS_SCRIPT_OBJECT);
        }
    }
    return null;
}
 
Example #13
Source File: JDK_8078414_Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCanNotConvertArbitraryClassToMirror() {
    assertCanNotConvert(Double.class, Map.class);
    assertCanNotConvert(Double.class, Bindings.class);
    assertCanNotConvert(Double.class, JSObject.class);
    assertCanNotConvert(Double.class, ScriptObjectMirror.class);
}
 
Example #14
Source File: ListAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static JSObject getJSObject(final Object obj, final Global global) {
    if (obj instanceof ScriptObject) {
        return (JSObject)ScriptObjectMirror.wrap(obj, global);
    } else if (obj instanceof JSObject) {
        return (JSObject)obj;
    }
    throw new IllegalArgumentException("ScriptObject or JSObject expected");
}
 
Example #15
Source File: JSObjectLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static Object jsObjectScopeCall(final JSObject jsObj, final Object thiz, final Object[] args) {
    final Object modifiedThiz;
    if (thiz == ScriptRuntime.UNDEFINED && !jsObj.isStrictFunction()) {
        final Global global = Context.getGlobal();
        modifiedThiz = ScriptObjectMirror.wrap(global, global);
    } else {
        modifiedThiz = thiz;
    }
    return jsObj.call(modifiedThiz, args);
}
 
Example #16
Source File: ScriptRuntime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an iterator over property identifiers used in the {@code for...in} statement. Note that the ECMAScript
 * 5.1 specification, chapter 12.6.4. uses the terminology "property names", which seems to imply that the property
 * identifiers are expected to be strings, but this is not actually spelled out anywhere, and Nashorn will in some
 * cases deviate from this. Namely, we guarantee to always return an iterator over {@link String} values for any
 * built-in JavaScript object. We will however return an iterator over {@link Integer} objects for native Java
 * arrays and {@link List} objects, as well as arbitrary objects representing keys of a {@link Map}. Therefore, the
 * expression {@code typeof i} within a {@code for(i in obj)} statement can return something other than
 * {@code string} when iterating over native Java arrays, {@code List}, and {@code Map} objects.
 * @param obj object to iterate on.
 * @return iterator over the object's property names.
 */
public static Iterator<?> toPropertyIterator(final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).propertyIterator();
    }

    if (obj != null && obj.getClass().isArray()) {
        return new RangeIterator(Array.getLength(obj));
    }

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

    if (obj instanceof List) {
        return new RangeIterator(((List<?>)obj).size());
    }

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

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

    return Collections.emptyIterator();
}
 
Example #17
Source File: NativeJSON.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Object getProperty(final Object holder, final Object key) {
    if (holder instanceof ScriptObject) {
        return ((ScriptObject)holder).get(key);
    } else if (holder instanceof JSObject) {
        JSObject jsObj = (JSObject)holder;
        if (key instanceof Integer) {
            return jsObj.getSlot((Integer)key);
        } else {
            return jsObj.getMember(Objects.toString(key));
        }
    } else {
        return new AssertionError("should not reach here");
    }
}
 
Example #18
Source File: TestPrintJSON.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
        String json = output.getStdout();

        // Parse JSON using Nashorn
        String statement = "var jsonObject = " + json;
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("nashorn");
        engine.eval(statement);
        JSObject o = (JSObject) engine.get("jsonObject");
        JSObject recording = (JSObject) o.getMember("recording");
        JSObject jsonEvents = (JSObject) recording.getMember("events");

        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        // Verify events are equal
        Iterator<RecordedEvent> it = events.iterator();

        for (Object jsonEvent : jsonEvents.values()) {
            RecordedEvent recordedEvent = it.next();
            String typeName = recordedEvent.getEventType().getName();
            Asserts.assertEquals(typeName, ((JSObject) jsonEvent).getMember("type").toString());
            assertEquals(jsonEvent, recordedEvent);
        }
        Asserts.assertFalse(events.size() != jsonEvents.values().size(), "Incorrect number of events");
    }
 
Example #19
Source File: JDK_8078414_Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCanNotConvertArbitraryClassToMirror() {
    assertCanNotConvert(Double.class, Map.class);
    assertCanNotConvert(Double.class, Bindings.class);
    assertCanNotConvert(Double.class, JSObject.class);
    assertCanNotConvert(Double.class, ScriptObjectMirror.class);
}
 
Example #20
Source File: ListAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ListAdapter(final JSObject obj, final Global global) {
    if (global == null) {
        throw new IllegalStateException(ECMAErrors.getMessage("list.adapter.null.global"));
    }

    this.obj = obj;
    this.global = global;
}
 
Example #21
Source File: ScriptObjectMirrorTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void topLevelAnonFuncStatement() throws Exception {
    final ScriptEngineManager engineManager = new ScriptEngineManager();
    final ScriptEngine e = engineManager.getEngineByName("nashorn");
    final JSObject func = (JSObject)e.eval("function(x) { return x + ' world' }");
    assertTrue(func.isFunction());
    assertEquals(func.call(e.eval("this"), "hello"), "hello world");
}
 
Example #22
Source File: ScriptRuntime.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 11.4.1 - delete operation, generic implementation
 *
 * @param obj       object with property to delete
 * @param property  property to delete
 * @param strict    are we in strict mode
 *
 * @return true if property was successfully found and deleted
 */
public static boolean DELETE(final Object obj, final Object property, final Object strict) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).delete(property, Boolean.TRUE.equals(strict));
    }

    if (obj instanceof Undefined) {
        return ((Undefined)obj).delete(property, false);
    }

    if (obj == null) {
        throw typeError("cant.delete.property", safeToString(property), "null");
    }

    if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).delete(property);
    }

    if (JSType.isPrimitive(obj)) {
        return ((ScriptObject) JSType.toScriptObject(obj)).delete(property, Boolean.TRUE.equals(strict));
    }

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

    // if object is not reference type, vacuously delete is successful.
    return true;
}
 
Example #23
Source File: JSObjectLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static Object callToApply(final MethodHandle mh, final JSObject obj, final Object thiz, final Object... args) {
    assert args.length >= 2;
    final Object   receiver  = args[0];
    final Object[] arguments = new Object[args.length - 1];
    System.arraycopy(args, 1, arguments, 0, arguments.length);
    try {
        return mh.invokeExact(obj, thiz, new Object[] { receiver, arguments });
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: JSObjectLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static boolean canLinkTypeStatic(final Class<?> type) {
    // can link JSObject also handles Map, Bindings to make
    // sure those are not JSObjects.
    return Map.class.isAssignableFrom(type) ||
           Bindings.class.isAssignableFrom(type) ||
           JSObject.class.isAssignableFrom(type);
}
 
Example #25
Source File: ArrayLikeIterator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #26
Source File: ConsStringTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testConsStringFromMirror() throws ScriptException {
    final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
    final Map<Object, Object> m = new HashMap<>();
    e.eval("var x = 'f'; x += 'oo'; var obj = {x: x};");
    assertEquals("foo", ((JSObject)b.get("obj")).getMember("x"));
}
 
Example #27
Source File: NativeJSON.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Object getProperty(final Object holder, final Object key) {
    if (holder instanceof ScriptObject) {
        return ((ScriptObject)holder).get(key);
    } else if (holder instanceof JSObject) {
        final JSObject jsObj = (JSObject)holder;
        if (key instanceof Integer) {
            return jsObj.getSlot((Integer)key);
        } else {
            return jsObj.getMember(Objects.toString(key));
        }
    } else {
        return new AssertionError("should not reach here");
    }
}
 
Example #28
Source File: JSObjectLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static Object jsObjectScopeCall(final JSObject jsObj, final Object thiz, final Object[] args) {
    final Object modifiedThiz;
    if (thiz == ScriptRuntime.UNDEFINED && !jsObj.isStrictFunction()) {
        final Global global = Context.getGlobal();
        modifiedThiz = ScriptObjectMirror.wrap(global, global);
    } else {
        modifiedThiz = thiz;
    }
    return jsObj.call(modifiedThiz, args);
}
 
Example #29
Source File: ConsStringTest.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testConsStringFromMirror() throws ScriptException {
    final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
    //final Map<Object, Object> m = new HashMap<>();
    e.eval("var x = 'f'; x += 'oo'; var obj = {x: x};");
    assertEquals("foo", ((JSObject)b.get("obj")).getMember("x"));
}
 
Example #30
Source File: ScriptRuntime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 11.4.1 - delete operation, generic implementation
 *
 * @param obj       object with property to delete
 * @param property  property to delete
 * @param strict    are we in strict mode
 *
 * @return true if property was successfully found and deleted
 */
public static boolean DELETE(final Object obj, final Object property, final Object strict) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).delete(property, Boolean.TRUE.equals(strict));
    }

    if (obj instanceof Undefined) {
        return ((Undefined)obj).delete(property, false);
    }

    if (obj == null) {
        throw typeError("cant.delete.property", safeToString(property), "null");
    }

    if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).delete(property);
    }

    if (JSType.isPrimitive(obj)) {
        return ((ScriptObject) JSType.toScriptObject(obj)).delete(property, Boolean.TRUE.equals(strict));
    }

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

    // if object is not reference type, vacuously delete is successful.
    return true;
}