71 * @param strict strict mode execution.
72 * @return True if deleted.
73 */
74 @Override
75 public boolean delete(final Object key, final boolean strict) {
76 final ScriptObject self = expression;
77 final String propName = JSType.toString(key);
78
79 final FindProperty find = self.findProperty(propName, true);
80
81 if (find != null) {
82 return self.delete(propName, strict);
83 }
84
85 return false;
86 }
87
88
89 @Override
90 public GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request) {
91 // With scopes can never be observed outside of Nashorn code, so all call sites that can address it will of
92 // necessity have a Nashorn descriptor - it is safe to cast.
93 final NashornCallSiteDescriptor ndesc = (NashornCallSiteDescriptor)desc;
94 FindProperty find = null;
95 GuardedInvocation link = null;
96 ScriptObject self = null;
97
98 final boolean isNamedOperation;
99 final String name;
100 if(desc.getNameTokenCount() > 2) {
101 isNamedOperation = true;
102 name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
103 } else {
104 isNamedOperation = false;
105 name = null;
106 }
107
108 self = expression;
109 if (isNamedOperation) {
110 find = self.findProperty(name, true);
248 // Make sure getMethod will bind the script functions it receives to WithObject.expression
249 MH.foldArguments(linkReturnsFunction ? BIND_TO_EXPRESSION_FN : BIND_TO_EXPRESSION_OBJ,
250 filter(linkInvocation.asType(linkType.changeReturnType(
251 linkReturnsFunction ? ScriptFunction.class : Object.class)), WITHEXPRESSIONFILTER)),
252 // No clever things for the guard -- it is still identically filtered.
253 filterGuard(link, WITHEXPRESSIONFILTER));
254 }
255
256 private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) {
257 final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER);
258 return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER),
259 NashornGuards.combineGuards(expressionGuard(name, owner), filterGuard(newLink, WITHSCOPEFILTER)));
260 }
261
262 private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
263 final MethodHandle test = link.getGuard();
264 return test == null ? null : filter(test, filter);
265 }
266
267 private static MethodHandle filter(final MethodHandle mh, final MethodHandle filter) {
268 return MH.filterArguments(mh, 0, filter);
269 }
270
271 /**
272 * Drops the WithObject wrapper from the expression.
273 * @param receiver WithObject wrapper.
274 * @return The with expression.
275 */
276 public static Object withFilterExpression(final Object receiver) {
277 return ((WithObject)receiver).expression;
278 }
279
280 @SuppressWarnings("unused")
281 private static Object bindToExpression(final Object fn, final Object receiver) {
282 return fn instanceof ScriptFunction ? bindToExpression((ScriptFunction) fn, receiver) : fn;
283 }
284
285 private static Object bindToExpression(final ScriptFunction fn, final Object receiver) {
286 return fn.makeBoundFunction(withFilterExpression(receiver), new Object[0]);
287 }
288
|
71 * @param strict strict mode execution.
72 * @return True if deleted.
73 */
74 @Override
75 public boolean delete(final Object key, final boolean strict) {
76 final ScriptObject self = expression;
77 final String propName = JSType.toString(key);
78
79 final FindProperty find = self.findProperty(propName, true);
80
81 if (find != null) {
82 return self.delete(propName, strict);
83 }
84
85 return false;
86 }
87
88
89 @Override
90 public GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request) {
91 if (request.isCallSiteUnstable()) {
92 // Fall back to megamorphic invocation which performs a complete lookup each time without further relinking.
93 return super.lookup(desc, request);
94 }
95
96 // With scopes can never be observed outside of Nashorn code, so all call sites that can address it will of
97 // necessity have a Nashorn descriptor - it is safe to cast.
98 final NashornCallSiteDescriptor ndesc = (NashornCallSiteDescriptor)desc;
99 FindProperty find = null;
100 GuardedInvocation link = null;
101 ScriptObject self = null;
102
103 final boolean isNamedOperation;
104 final String name;
105 if(desc.getNameTokenCount() > 2) {
106 isNamedOperation = true;
107 name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
108 } else {
109 isNamedOperation = false;
110 name = null;
111 }
112
113 self = expression;
114 if (isNamedOperation) {
115 find = self.findProperty(name, true);
253 // Make sure getMethod will bind the script functions it receives to WithObject.expression
254 MH.foldArguments(linkReturnsFunction ? BIND_TO_EXPRESSION_FN : BIND_TO_EXPRESSION_OBJ,
255 filter(linkInvocation.asType(linkType.changeReturnType(
256 linkReturnsFunction ? ScriptFunction.class : Object.class)), WITHEXPRESSIONFILTER)),
257 // No clever things for the guard -- it is still identically filtered.
258 filterGuard(link, WITHEXPRESSIONFILTER));
259 }
260
261 private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) {
262 final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER);
263 return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER),
264 NashornGuards.combineGuards(expressionGuard(name, owner), filterGuard(newLink, WITHSCOPEFILTER)));
265 }
266
267 private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
268 final MethodHandle test = link.getGuard();
269 return test == null ? null : filter(test, filter);
270 }
271
272 private static MethodHandle filter(final MethodHandle mh, final MethodHandle filter) {
273 return MH.filterArguments(mh, 0, filter.asType(filter.type().changeReturnType(mh.type().parameterType(0))));
274 }
275
276 /**
277 * Drops the WithObject wrapper from the expression.
278 * @param receiver WithObject wrapper.
279 * @return The with expression.
280 */
281 public static Object withFilterExpression(final Object receiver) {
282 return ((WithObject)receiver).expression;
283 }
284
285 @SuppressWarnings("unused")
286 private static Object bindToExpression(final Object fn, final Object receiver) {
287 return fn instanceof ScriptFunction ? bindToExpression((ScriptFunction) fn, receiver) : fn;
288 }
289
290 private static Object bindToExpression(final ScriptFunction fn, final Object receiver) {
291 return fn.makeBoundFunction(withFilterExpression(receiver), new Object[0]);
292 }
293
|