43 import java.util.List;
44 import java.util.Map;
45 import java.util.Objects;
46 import java.util.concurrent.Callable;
47 import java.util.concurrent.ConcurrentHashMap;
48 import javax.script.ScriptContext;
49 import javax.script.ScriptEngine;
50 import jdk.internal.dynalink.CallSiteDescriptor;
51 import jdk.internal.dynalink.linker.GuardedInvocation;
52 import jdk.internal.dynalink.linker.LinkRequest;
53 import jdk.nashorn.api.scripting.ClassFilter;
54 import jdk.nashorn.api.scripting.ScriptObjectMirror;
55 import jdk.nashorn.internal.lookup.Lookup;
56 import jdk.nashorn.internal.objects.annotations.Attribute;
57 import jdk.nashorn.internal.objects.annotations.Getter;
58 import jdk.nashorn.internal.objects.annotations.Property;
59 import jdk.nashorn.internal.objects.annotations.ScriptClass;
60 import jdk.nashorn.internal.objects.annotations.Setter;
61 import jdk.nashorn.internal.runtime.Context;
62 import jdk.nashorn.internal.runtime.ECMAErrors;
63 import jdk.nashorn.internal.runtime.GlobalConstants;
64 import jdk.nashorn.internal.runtime.GlobalFunctions;
65 import jdk.nashorn.internal.runtime.JSType;
66 import jdk.nashorn.internal.runtime.NativeJavaPackage;
67 import jdk.nashorn.internal.runtime.PropertyDescriptor;
68 import jdk.nashorn.internal.runtime.PropertyMap;
69 import jdk.nashorn.internal.runtime.Scope;
70 import jdk.nashorn.internal.runtime.ScriptEnvironment;
71 import jdk.nashorn.internal.runtime.ScriptFunction;
72 import jdk.nashorn.internal.runtime.ScriptObject;
73 import jdk.nashorn.internal.runtime.ScriptRuntime;
74 import jdk.nashorn.internal.runtime.ScriptingFunctions;
75 import jdk.nashorn.internal.runtime.Specialization;
76 import jdk.nashorn.internal.runtime.arrays.ArrayData;
77 import jdk.nashorn.internal.runtime.linker.Bootstrap;
78 import jdk.nashorn.internal.runtime.linker.InvokeByName;
79 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
80 import jdk.nashorn.internal.runtime.regexp.RegExpResult;
81 import jdk.nashorn.internal.scripts.JO;
82 import jdk.nashorn.tools.ShellFunctions;
2184 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2185
2186 if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
2187 if (lexicalScope.hasOwnProperty(name)) {
2188 return lexicalScope.findGetMethod(desc, request, operator);
2189 }
2190 }
2191
2192 final GuardedInvocation invocation = super.findGetMethod(desc, request, operator);
2193
2194 // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
2195 // because those are invalidated per-key in the addBoundProperties method above.
2196 // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
2197 // assuming this only applies to global constants. If other non-inherited properties will
2198 // start using switchpoints some time in the future we'll have to revisit this.
2199 if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
2200 return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
2201 }
2202
2203 return invocation;
2204 }
2205
2206 @Override
2207 public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
2208 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2209
2210 if (lexicalScope != null && isScope) {
2211 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
2212 if (lexicalScope.hasOwnProperty(name)) {
2213 return lexicalScope.findSetMethod(desc, request);
2214 }
2215 }
2216
2217 final GuardedInvocation invocation = super.findSetMethod(desc, request);
2218
2219 if (isScope && context.getEnv()._es6) {
2220 return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
2221 }
2222
2223 return invocation;
|
43 import java.util.List;
44 import java.util.Map;
45 import java.util.Objects;
46 import java.util.concurrent.Callable;
47 import java.util.concurrent.ConcurrentHashMap;
48 import javax.script.ScriptContext;
49 import javax.script.ScriptEngine;
50 import jdk.internal.dynalink.CallSiteDescriptor;
51 import jdk.internal.dynalink.linker.GuardedInvocation;
52 import jdk.internal.dynalink.linker.LinkRequest;
53 import jdk.nashorn.api.scripting.ClassFilter;
54 import jdk.nashorn.api.scripting.ScriptObjectMirror;
55 import jdk.nashorn.internal.lookup.Lookup;
56 import jdk.nashorn.internal.objects.annotations.Attribute;
57 import jdk.nashorn.internal.objects.annotations.Getter;
58 import jdk.nashorn.internal.objects.annotations.Property;
59 import jdk.nashorn.internal.objects.annotations.ScriptClass;
60 import jdk.nashorn.internal.objects.annotations.Setter;
61 import jdk.nashorn.internal.runtime.Context;
62 import jdk.nashorn.internal.runtime.ECMAErrors;
63 import jdk.nashorn.internal.runtime.FindProperty;
64 import jdk.nashorn.internal.runtime.GlobalConstants;
65 import jdk.nashorn.internal.runtime.GlobalFunctions;
66 import jdk.nashorn.internal.runtime.JSType;
67 import jdk.nashorn.internal.runtime.NativeJavaPackage;
68 import jdk.nashorn.internal.runtime.PropertyDescriptor;
69 import jdk.nashorn.internal.runtime.PropertyMap;
70 import jdk.nashorn.internal.runtime.Scope;
71 import jdk.nashorn.internal.runtime.ScriptEnvironment;
72 import jdk.nashorn.internal.runtime.ScriptFunction;
73 import jdk.nashorn.internal.runtime.ScriptObject;
74 import jdk.nashorn.internal.runtime.ScriptRuntime;
75 import jdk.nashorn.internal.runtime.ScriptingFunctions;
76 import jdk.nashorn.internal.runtime.Specialization;
77 import jdk.nashorn.internal.runtime.arrays.ArrayData;
78 import jdk.nashorn.internal.runtime.linker.Bootstrap;
79 import jdk.nashorn.internal.runtime.linker.InvokeByName;
80 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
81 import jdk.nashorn.internal.runtime.regexp.RegExpResult;
82 import jdk.nashorn.internal.scripts.JO;
83 import jdk.nashorn.tools.ShellFunctions;
2185 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2186
2187 if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
2188 if (lexicalScope.hasOwnProperty(name)) {
2189 return lexicalScope.findGetMethod(desc, request, operator);
2190 }
2191 }
2192
2193 final GuardedInvocation invocation = super.findGetMethod(desc, request, operator);
2194
2195 // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
2196 // because those are invalidated per-key in the addBoundProperties method above.
2197 // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
2198 // assuming this only applies to global constants. If other non-inherited properties will
2199 // start using switchpoints some time in the future we'll have to revisit this.
2200 if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) {
2201 return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
2202 }
2203
2204 return invocation;
2205 }
2206
2207 @Override
2208 protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) {
2209 if (lexicalScope != null && start != this && start.isScope()) {
2210 final FindProperty find = lexicalScope.findProperty(key, false);
2211 if (find != null) {
2212 return find;
2213 }
2214 }
2215 return super.findProperty(key, deep, start);
2216 }
2217
2218 @Override
2219 public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) {
2220 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2221
2222 if (lexicalScope != null && isScope) {
2223 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
2224 if (lexicalScope.hasOwnProperty(name)) {
2225 return lexicalScope.findSetMethod(desc, request);
2226 }
2227 }
2228
2229 final GuardedInvocation invocation = super.findSetMethod(desc, request);
2230
2231 if (isScope && context.getEnv()._es6) {
2232 return invocation.addSwitchPoint(getLexicalScopeSwitchPoint());
2233 }
2234
2235 return invocation;
|