Java Code Examples for jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#isScope()

The following examples show how to use jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#isScope() . 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: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fall back if a function property is not found.
 * @param desc The call site descriptor
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String       name      = desc.getNameToken(2);
    final FindProperty find      = findProperty(NO_SUCH_METHOD_NAME, true);
    final boolean      scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find == null) {
        return noSuchProperty(desc, request);
    }

    final Object value = getObjectValue(find);
    if (! (value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object thiz = scopeCall && func.isStrict() ? ScriptRuntime.UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    return new GuardedInvocation(MH.dropArguments(MH.constant(ScriptFunction.class,
            func.makeBoundFunction(thiz, new Object[] { name })), 0, Object.class),
            null, NashornGuards.getMapGuard(getMap()));
}
 
Example 2
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 3
Source File: Global.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request, operator);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 4
Source File: Global.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = NashornCallSiteDescriptor.getOperand(desc);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 5
Source File: Global.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 6
Source File: Global.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request, operator);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 7
Source File: Global.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 8
Source File: Global.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope) {
        final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findSetMethod(desc, request);
        }
    }

    final GuardedInvocation invocation = super.findSetMethod(desc, request);

    if (isScope && context.getEnv()._es6) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 9
Source File: Global.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request, operator);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 10
Source File: Global.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final boolean isScope = NashornCallSiteDescriptor.isScope(desc);

    if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
        if (lexicalScope.hasOwnProperty(name)) {
            return lexicalScope.findGetMethod(desc, request, operator);
        }
    }

    final GuardedInvocation invocation =  super.findGetMethod(desc, request, operator);

    // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
    // because those are invalidated per-key in the addBoundProperties method above.
    // We therefore check if the invocation does already have a switchpoint and the property is non-inherited,
    // assuming this only applies to global constants. If other non-inherited properties will
    // start using switchpoints some time in the future we'll have to revisit this.
    if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
        return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
    }

    return invocation;
}
 
Example 11
Source File: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a property is not found.
 * @param desc the call site descriptor.
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
@SuppressWarnings("null")
public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    final FindProperty find = findProperty(NO_SUCH_PROPERTY_NAME, true);
    final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find != null) {
        final Object   value        = getObjectValue(find);
        ScriptFunction func         = null;
        MethodHandle   methodHandle = null;

        if (value instanceof ScriptFunction) {
            func = (ScriptFunction)value;
            methodHandle = getCallMethodHandle(func, desc.getMethodType(), name);
        }

        if (methodHandle != null) {
            if (scopeAccess && func.isStrict()) {
                methodHandle = bindTo(methodHandle, UNDEFINED);
            }
            return new GuardedInvocation(methodHandle,
                    find.isInherited()? getMap().getProtoGetSwitchPoint(proto, NO_SUCH_PROPERTY_NAME) : null,
                    getKnownFunctionPropertyGuard(getMap(), find.getGetter(Object.class), find.getOwner(), func));
        }
    }

    if (scopeAccess) {
        throw referenceError("not.defined", name);
    }

    return createEmptyGetter(desc, name);
}
 
Example 12
Source File: ScriptObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a function property is not found.
 * @param desc The call site descriptor
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String       name      = desc.getNameToken(2);
    final FindProperty find      = findProperty(NO_SUCH_METHOD_NAME, true);
    final boolean      scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find == null) {
        return noSuchProperty(desc, request);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    final Object value = find.getObjectValue();
    if (!(value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, explicitInstanceOfCheck, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object         thiz = scopeCall && func.isStrict() ? UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    // Since we're binding this we must use an identity guard here.
    return new GuardedInvocation(
            MH.dropArguments(
                    MH.constant(
                            ScriptFunction.class,
                            func.createBound(thiz, new Object[] { name })),
                    0,
                    Object.class),
            NashornGuards.combineGuards(
                    NashornGuards.getIdentityGuard(this),
                    NashornGuards.getMapGuard(getMap(), true)));
}
 
Example 13
Source File: ScriptObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a function property is not found.
 * @param desc The call site descriptor
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String       name      = desc.getNameToken(2);
    final FindProperty find      = findProperty(NO_SUCH_METHOD_NAME, true);
    final boolean      scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find == null) {
        return noSuchProperty(desc, request);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    final Object value = find.getObjectValue();
    if (!(value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, explicitInstanceOfCheck, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object         thiz = scopeCall && func.isStrict() ? UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    // Since we're binding this we must use an identity guard here.
    return new GuardedInvocation(
            MH.dropArguments(
                    MH.constant(
                            ScriptFunction.class,
                            func.createBound(thiz, new Object[] { name })),
                    0,
                    Object.class),
            NashornGuards.combineGuards(
                    NashornGuards.getIdentityGuard(this),
                    NashornGuards.getMapGuard(getMap(), true)));
}
 
Example 14
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a function property is not found.
 * @param desc The call site descriptor
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String       name      = desc.getNameToken(2);
    final FindProperty find      = findProperty(NO_SUCH_METHOD_NAME, true);
    final boolean      scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find == null) {
        return noSuchProperty(desc, request);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    final Object value = find.getObjectValue();
    if (!(value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, explicitInstanceOfCheck, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object         thiz = scopeCall && func.isStrict() ? UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    // Since we're binding this we must use an identity guard here.
    return new GuardedInvocation(
            MH.dropArguments(
                    MH.constant(
                            ScriptFunction.class,
                            func.createBound(thiz, new Object[] { name })),
                    0,
                    Object.class),
            NashornGuards.combineGuards(
                    NashornGuards.getIdentityGuard(this),
                    NashornGuards.getMapGuard(getMap(), true)));
}
 
Example 15
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fall back if a function property is not found.
 * @param desc The call site descriptor
 * @param request the link request
 * @return GuardedInvocation to be invoked at call site.
 */
public GuardedInvocation noSuchMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String       name      = desc.getNameToken(2);
    final FindProperty find      = findProperty(NO_SUCH_METHOD_NAME, true);
    final boolean      scopeCall = isScope() && NashornCallSiteDescriptor.isScope(desc);

    if (find == null) {
        return noSuchProperty(desc, request);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    final Object value = find.getObjectValue();
    if (!(value instanceof ScriptFunction)) {
        return createEmptyGetter(desc, explicitInstanceOfCheck, name);
    }

    final ScriptFunction func = (ScriptFunction)value;
    final Object         thiz = scopeCall && func.isStrict() ? UNDEFINED : this;
    // TODO: It'd be awesome if we could bind "name" without binding "this".
    // Since we're binding this we must use an identity guard here.
    return new GuardedInvocation(
            MH.dropArguments(
                    MH.constant(
                            ScriptFunction.class,
                            func.createBound(thiz, new Object[] { name })),
                    0,
                    Object.class),
            NashornGuards.combineGuards(
                    NashornGuards.getIdentityGuard(this),
                    NashornGuards.getMapGuard(getMap(), true)));
}
 
Example 16
Source File: SetMethodCreator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void checkStrictCreateNewVariable() {
    // In strict mode, assignment can not create a new variable.
    // See also ECMA Annex C item 4. ReferenceError is thrown.
    if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
        throw referenceError("not.defined", getName());
    }
}
 
Example 17
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Find the appropriate SET method for an invoke dynamic call.
 *
 * @param desc    the call site descriptor
 * @param request the link request
 *
 * @return GuardedInvocation to be invoked at call site.
 */
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);

    if (request.isCallSiteUnstable() || hasWithScope()) {
        return findMegaMorphicSetMethod(desc, name);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    /*
     * If doing property set on a scope object, we should stop proto search on the first
     * non-scope object. Without this, for example, when assigning "toString" on global scope,
     * we'll end up assigning it on it's proto - which is Object.prototype.toString !!
     *
     * toString = function() { print("global toString"); } // don't affect Object.prototype.toString
     */
    FindProperty find = findProperty(name, true, this);

    // If it's not a scope search, then we don't want any inherited properties except those with user defined accessors.
    if (find != null && find.isInherited() && !(find.getProperty() instanceof UserAccessorProperty)) {
        // We should still check if inherited data property is not writable
        if (isExtensible() && !find.getProperty().isWritable()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
        // Otherwise, forget the found property unless this is a scope callsite and the owner is a scope object as well.
        if (!NashornCallSiteDescriptor.isScope(desc) || !find.getOwner().isScope()) {
            find = null;
        }
    }

    if (find != null) {
        if (!find.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(desc)) {
            if (NashornCallSiteDescriptor.isScope(desc) && find.getProperty().isLexicalBinding()) {
                throw typeError("assign.constant", name); // Overwriting ES6 const should throw also in non-strict mode.
            }
            // Existing, non-writable property
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
    } else {
        if (!isExtensible()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "object.non.extensible", false);
        }
    }

    final GuardedInvocation inv = new SetMethodCreator(this, find, desc, request).createGuardedInvocation(findBuiltinSwitchPoint(name));

    final GlobalConstants globalConstants = getGlobalConstants();
    if (globalConstants != null) {
        final GuardedInvocation cinv = globalConstants.findSetMethod(find, this, inv, desc, request);
        if (cinv != null) {
            return cinv;
        }
    }

    return inv;
}
 
Example 18
Source File: ScriptObject.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Find the appropriate SET method for an invoke dynamic call.
 *
 * @param desc    the call site descriptor
 * @param request the link request
 *
 * @return GuardedInvocation to be invoked at call site.
 */
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = NashornCallSiteDescriptor.getOperand(desc);

    if (request.isCallSiteUnstable() || hasWithScope()) {
        return findMegaMorphicSetMethod(desc, name);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    /*
     * If doing property set on a scope object, we should stop proto search on the first
     * non-scope object. Without this, for example, when assigning "toString" on global scope,
     * we'll end up assigning it on it's proto - which is Object.prototype.toString !!
     *
     * toString = function() { print("global toString"); } // don't affect Object.prototype.toString
     */
    FindProperty find = findProperty(name, true, NashornCallSiteDescriptor.isScope(desc), this);

    // If it's not a scope search, then we don't want any inherited properties except those with user defined accessors.
    if (find != null && find.isInheritedOrdinaryProperty()) {
        // We should still check if inherited data property is not writable
        if (isExtensible() && !find.getProperty().isWritable()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
        // Otherwise, forget the found property unless this is a scope callsite and the owner is a scope object as well.
        if (!NashornCallSiteDescriptor.isScope(desc) || !find.getOwner().isScope()) {
            find = null;
        }
    }

    if (find != null) {
        if (!find.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(desc)) {
            if (NashornCallSiteDescriptor.isScope(desc) && find.getProperty().isLexicalBinding()) {
                throw typeError("assign.constant", name); // Overwriting ES6 const should throw also in non-strict mode.
            }
            // Existing, non-writable data property
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
        if (!find.getProperty().hasNativeSetter()) {
            // Existing accessor property without setter
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.has.no.setter", true);
        }
    } else {
        if (!isExtensible()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "object.non.extensible", false);
        }
    }

    final GuardedInvocation inv = new SetMethodCreator(this, find, desc, request).createGuardedInvocation(findBuiltinSwitchPoint(name));

    final GlobalConstants globalConstants = getGlobalConstants();
    if (globalConstants != null) {
        final GuardedInvocation cinv = globalConstants.findSetMethod(find, this, inv, desc, request);
        if (cinv != null) {
            return cinv;
        }
    }

    return inv;
}
 
Example 19
Source File: ScriptObject.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Find the appropriate SET method for an invoke dynamic call.
 *
 * @param desc    the call site descriptor
 * @param request the link request
 *
 * @return GuardedInvocation to be invoked at call site.
 */
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);

    if (request.isCallSiteUnstable() || hasWithScope()) {
        return findMegaMorphicSetMethod(desc, name);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    /*
     * If doing property set on a scope object, we should stop proto search on the first
     * non-scope object. Without this, for example, when assigning "toString" on global scope,
     * we'll end up assigning it on it's proto - which is Object.prototype.toString !!
     *
     * toString = function() { print("global toString"); } // don't affect Object.prototype.toString
     */
    FindProperty find = findProperty(name, true, this);

    // If it's not a scope search, then we don't want any inherited properties except those with user defined accessors.
    if (find != null && find.isInherited() && !(find.getProperty() instanceof UserAccessorProperty)) {
        // We should still check if inherited data property is not writable
        if (isExtensible() && !find.getProperty().isWritable()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
        // Otherwise, forget the found property unless this is a scope callsite and the owner is a scope object as well.
        if (!NashornCallSiteDescriptor.isScope(desc) || !find.getOwner().isScope()) {
            find = null;
        }
    }

    if (find != null) {
        if (!find.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(desc)) {
            if (NashornCallSiteDescriptor.isScope(desc) && find.getProperty().isLexicalBinding()) {
                throw typeError("assign.constant", name); // Overwriting ES6 const should throw also in non-strict mode.
            }
            // Existing, non-writable property
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
    } else {
        if (!isExtensible()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "object.non.extensible", false);
        }
    }

    final GuardedInvocation inv = new SetMethodCreator(this, find, desc, request).createGuardedInvocation(findBuiltinSwitchPoint(name));

    final GlobalConstants globalConstants = getGlobalConstants();
    if (globalConstants != null) {
        final GuardedInvocation cinv = globalConstants.findSetMethod(find, this, inv, desc, request);
        if (cinv != null) {
            return cinv;
        }
    }

    return inv;
}
 
Example 20
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Find the appropriate SET method for an invoke dynamic call.
 *
 * @param desc    the call site descriptor
 * @param request the link request
 *
 * @return GuardedInvocation to be invoked at call site.
 */
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
    final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);

    if (request.isCallSiteUnstable() || hasWithScope()) {
        return findMegaMorphicSetMethod(desc, name);
    }

    final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request);

    /*
     * If doing property set on a scope object, we should stop proto search on the first
     * non-scope object. Without this, for example, when assigning "toString" on global scope,
     * we'll end up assigning it on it's proto - which is Object.prototype.toString !!
     *
     * toString = function() { print("global toString"); } // don't affect Object.prototype.toString
     */
    FindProperty find = findProperty(name, true, this);

    // If it's not a scope search, then we don't want any inherited properties except those with user defined accessors.
    if (find != null && find.isInherited() && !(find.getProperty() instanceof UserAccessorProperty)) {
        // We should still check if inherited data property is not writable
        if (isExtensible() && !find.getProperty().isWritable()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
        // Otherwise, forget the found property unless this is a scope callsite and the owner is a scope object as well.
        if (!NashornCallSiteDescriptor.isScope(desc) || !find.getOwner().isScope()) {
            find = null;
        }
    }

    if (find != null) {
        if (!find.getProperty().isWritable() && !NashornCallSiteDescriptor.isDeclaration(desc)) {
            if (NashornCallSiteDescriptor.isScope(desc) && find.getProperty().isLexicalBinding()) {
                throw typeError("assign.constant", name); // Overwriting ES6 const should throw also in non-strict mode.
            }
            // Existing, non-writable property
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true);
        }
    } else {
        if (!isExtensible()) {
            return createEmptySetMethod(desc, explicitInstanceOfCheck, "object.non.extensible", false);
        }
    }

    final GuardedInvocation inv = new SetMethodCreator(this, find, desc, request).createGuardedInvocation(findBuiltinSwitchPoint(name));

    final GlobalConstants globalConstants = getGlobalConstants();
    if (globalConstants != null) {
        final GuardedInvocation cinv = globalConstants.findSetMethod(find, this, inv, desc, request);
        if (cinv != null) {
            return cinv;
        }
    }

    return inv;
}