OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 9196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9207 // explicitly via a with-statement. | 9207 // explicitly via a with-statement. |
9208 Object* constructor = holder->map()->constructor(); | 9208 Object* constructor = holder->map()->constructor(); |
9209 if (constructor != context_extension_function) return holder; | 9209 if (constructor != context_extension_function) return holder; |
9210 // Fall back to using the global object as the implicit receiver if | 9210 // Fall back to using the global object as the implicit receiver if |
9211 // the property turns out to be a local variable allocated in a | 9211 // the property turns out to be a local variable allocated in a |
9212 // context extension object - introduced via eval. | 9212 // context extension object - introduced via eval. |
9213 return isolate->heap()->undefined_value(); | 9213 return isolate->heap()->undefined_value(); |
9214 } | 9214 } |
9215 | 9215 |
9216 | 9216 |
| 9217 static ObjectPair LoadWithContextSlot(Isolate* isolate, Handle<String> name, |
| 9218 Handle<JSReceiver> object, |
| 9219 Handle<Object> receiver_handle) { |
| 9220 Handle<JSReceiver> object_receiver = object; |
| 9221 Handle<Symbol> unscopables_symbol( |
| 9222 isolate->native_context()->unscopables_symbol(), isolate); |
| 9223 |
| 9224 while (true) { |
| 9225 PropertyAttributes name_attrs = |
| 9226 JSReceiver::GetOwnPropertyAttributes(object, name); |
| 9227 |
| 9228 if (name_attrs != ABSENT) { |
| 9229 PropertyAttributes unscopables_attrs = |
| 9230 JSReceiver::GetOwnPropertyAttributes(object, unscopables_symbol); |
| 9231 PropertyAttributes blocked_attrs = ABSENT; |
| 9232 if (unscopables_attrs != ABSENT) { |
| 9233 Handle<Object> unscopables_object; |
| 9234 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 9235 isolate, unscopables_object, |
| 9236 Object::GetProperty(object, unscopables_symbol), |
| 9237 MakePair(isolate->heap()->exception(), NULL)); |
| 9238 |
| 9239 if (unscopables_object->IsSpecObject()) { |
| 9240 blocked_attrs = JSReceiver::GetOwnPropertyAttributes( |
| 9241 Handle<JSReceiver>::cast(unscopables_object), name); |
| 9242 } |
| 9243 } |
| 9244 |
| 9245 if (blocked_attrs == ABSENT) { |
| 9246 Handle<Object> value; |
| 9247 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 9248 isolate, value, |
| 9249 Object::GetPropertyWithReceiver(object, object_receiver, name), |
| 9250 MakePair(isolate->heap()->exception(), NULL)); |
| 9251 return MakePair(*value, *receiver_handle); |
| 9252 } |
| 9253 } |
| 9254 |
| 9255 Object* prototype = object->GetPrototype(); |
| 9256 if (prototype->IsNull()) { |
| 9257 break; |
| 9258 } |
| 9259 ASSERT(prototype->IsSpecObject()); |
| 9260 object = handle(JSReceiver::cast(prototype), isolate); |
| 9261 } |
| 9262 |
| 9263 // The property doesn't exist - return undefined. |
| 9264 return MakePair(isolate->heap()->undefined_value(), |
| 9265 isolate->heap()->undefined_value()); |
| 9266 } |
| 9267 |
| 9268 |
9217 static ObjectPair LoadContextSlotHelper(Arguments args, | 9269 static ObjectPair LoadContextSlotHelper(Arguments args, |
9218 Isolate* isolate, | 9270 Isolate* isolate, |
9219 bool throw_error) { | 9271 bool throw_error) { |
9220 HandleScope scope(isolate); | 9272 HandleScope scope(isolate); |
9221 ASSERT_EQ(2, args.length()); | 9273 ASSERT_EQ(2, args.length()); |
9222 | 9274 |
9223 if (!args[0]->IsContext() || !args[1]->IsString()) { | 9275 if (!args[0]->IsContext() || !args[1]->IsString()) { |
9224 return MakePair(isolate->ThrowIllegalOperation(), NULL); | 9276 return MakePair(isolate->ThrowIllegalOperation(), NULL); |
9225 } | 9277 } |
9226 Handle<Context> context = args.at<Context>(0); | 9278 Handle<Context> context = args.at<Context>(0); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9281 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder); | 9333 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder); |
9282 ASSERT(object->IsJSProxy() || JSReceiver::HasProperty(object, name)); | 9334 ASSERT(object->IsJSProxy() || JSReceiver::HasProperty(object, name)); |
9283 // GetProperty below can cause GC. | 9335 // GetProperty below can cause GC. |
9284 Handle<Object> receiver_handle( | 9336 Handle<Object> receiver_handle( |
9285 object->IsGlobalObject() | 9337 object->IsGlobalObject() |
9286 ? Object::cast(isolate->heap()->undefined_value()) | 9338 ? Object::cast(isolate->heap()->undefined_value()) |
9287 : object->IsJSProxy() ? static_cast<Object*>(*object) | 9339 : object->IsJSProxy() ? static_cast<Object*>(*object) |
9288 : ComputeReceiverForNonGlobal(isolate, JSObject::cast(*object)), | 9340 : ComputeReceiverForNonGlobal(isolate, JSObject::cast(*object)), |
9289 isolate); | 9341 isolate); |
9290 | 9342 |
| 9343 if (FLAG_harmony_unscopables && context->IsWithContext()) { |
| 9344 return LoadWithContextSlot(isolate, name, object, receiver_handle); |
| 9345 } |
| 9346 |
9291 // No need to unhole the value here. This is taken care of by the | 9347 // No need to unhole the value here. This is taken care of by the |
9292 // GetProperty function. | 9348 // GetProperty function. |
9293 Handle<Object> value; | 9349 Handle<Object> value; |
9294 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 9350 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
9295 isolate, value, | 9351 isolate, value, |
9296 Object::GetProperty(object, name), | 9352 Object::GetProperty(object, name), |
9297 MakePair(isolate->heap()->exception(), NULL)); | 9353 MakePair(isolate->heap()->exception(), NULL)); |
9298 return MakePair(*value, *receiver_handle); | 9354 return MakePair(*value, *receiver_handle); |
9299 } | 9355 } |
9300 | 9356 |
(...skipping 5804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15105 } | 15161 } |
15106 return NULL; | 15162 return NULL; |
15107 } | 15163 } |
15108 | 15164 |
15109 | 15165 |
15110 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15166 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15111 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15167 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15112 } | 15168 } |
15113 | 15169 |
15114 } } // namespace v8::internal | 15170 } } // namespace v8::internal |
OLD | NEW |