OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (attributes != ABSENT) { | 258 if (attributes != ABSENT) { |
259 // The name was declared before; check for conflicting re-declarations. | 259 // The name was declared before; check for conflicting re-declarations. |
260 if (is_const || (attributes & READ_ONLY) != 0) { | 260 if (is_const || (attributes & READ_ONLY) != 0) { |
261 return ThrowRedeclarationError(isolate, name); | 261 return ThrowRedeclarationError(isolate, name); |
262 } | 262 } |
263 | 263 |
264 // Skip var re-declarations. | 264 // Skip var re-declarations. |
265 if (is_var) return isolate->heap()->undefined_value(); | 265 if (is_var) return isolate->heap()->undefined_value(); |
266 | 266 |
267 DCHECK(is_function); | 267 DCHECK(is_function); |
268 if (index >= 0) { | 268 if (index != Context::kNotFound) { |
269 DCHECK(holder.is_identical_to(context)); | 269 DCHECK(holder.is_identical_to(context)); |
270 context->set(index, *initial_value); | 270 context->set(index, *initial_value); |
271 return isolate->heap()->undefined_value(); | 271 return isolate->heap()->undefined_value(); |
272 } | 272 } |
273 | 273 |
274 object = Handle<JSObject>::cast(holder); | 274 object = Handle<JSObject>::cast(holder); |
275 | 275 |
276 } else if (context->has_extension()) { | 276 } else if (context->has_extension()) { |
277 // Sloppy varblock contexts might not have an extension object yet, | 277 // Sloppy varblock contexts might not have an extension object yet, |
278 // in which case their extension is a ScopeInfo. | 278 // in which case their extension is a ScopeInfo. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 PropertyAttributes attributes; | 339 PropertyAttributes attributes; |
340 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; | 340 ContextLookupFlags flags = DONT_FOLLOW_CHAINS; |
341 BindingFlags binding_flags; | 341 BindingFlags binding_flags; |
342 Handle<Object> holder = | 342 Handle<Object> holder = |
343 context->Lookup(name, flags, &index, &attributes, &binding_flags); | 343 context->Lookup(name, flags, &index, &attributes, &binding_flags); |
344 if (holder.is_null()) { | 344 if (holder.is_null()) { |
345 // In case of JSProxy, an exception might have been thrown. | 345 // In case of JSProxy, an exception might have been thrown. |
346 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 346 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
347 } | 347 } |
348 | 348 |
349 if (index >= 0) { | 349 if (index != Context::kNotFound) { |
350 DCHECK(holder->IsContext()); | 350 DCHECK(holder->IsContext()); |
351 // Property was found in a context. Perform the assignment if the constant | 351 // Property was found in a context. Perform the assignment if the constant |
352 // was uninitialized. | 352 // was uninitialized. |
353 Handle<Context> context = Handle<Context>::cast(holder); | 353 Handle<Context> context = Handle<Context>::cast(holder); |
354 DCHECK((attributes & READ_ONLY) != 0); | 354 DCHECK((attributes & READ_ONLY) != 0); |
355 if (context->get(index)->IsTheHole()) context->set(index, *value); | 355 if (context->get(index)->IsTheHole()) context->set(index, *value); |
356 return *value; | 356 return *value; |
357 } | 357 } |
358 | 358 |
359 PropertyAttributes attr = | 359 PropertyAttributes attr = |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 int index; | 943 int index; |
944 PropertyAttributes attributes; | 944 PropertyAttributes attributes; |
945 ContextLookupFlags flags = FOLLOW_CHAINS; | 945 ContextLookupFlags flags = FOLLOW_CHAINS; |
946 BindingFlags binding_flags; | 946 BindingFlags binding_flags; |
947 Handle<Object> holder = | 947 Handle<Object> holder = |
948 context->Lookup(name, flags, &index, &attributes, &binding_flags); | 948 context->Lookup(name, flags, &index, &attributes, &binding_flags); |
949 if (isolate->has_pending_exception()) { | 949 if (isolate->has_pending_exception()) { |
950 return MakePair(isolate->heap()->exception(), NULL); | 950 return MakePair(isolate->heap()->exception(), NULL); |
951 } | 951 } |
952 | 952 |
953 // If the index is non-negative, the slot has been found in a context. | 953 if (index != Context::kNotFound) { |
954 if (index >= 0) { | |
955 DCHECK(holder->IsContext()); | 954 DCHECK(holder->IsContext()); |
956 // If the "property" we were looking for is a local variable, the | 955 // If the "property" we were looking for is a local variable, the |
957 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. | 956 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. |
958 Handle<Object> receiver = isolate->factory()->undefined_value(); | 957 Handle<Object> receiver = isolate->factory()->undefined_value(); |
959 Object* value = Context::cast(*holder)->get(index); | 958 Object* value = Context::cast(*holder)->get(index); |
960 // Check for uninitialized bindings. | 959 // Check for uninitialized bindings. |
961 switch (binding_flags) { | 960 switch (binding_flags) { |
962 case MUTABLE_CHECK_INITIALIZED: | 961 case MUTABLE_CHECK_INITIALIZED: |
963 case IMMUTABLE_CHECK_INITIALIZED_HARMONY: | 962 case IMMUTABLE_CHECK_INITIALIZED_HARMONY: |
964 if (value->IsTheHole()) { | 963 if (value->IsTheHole()) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 ContextLookupFlags flags = FOLLOW_CHAINS; | 1045 ContextLookupFlags flags = FOLLOW_CHAINS; |
1047 BindingFlags binding_flags; | 1046 BindingFlags binding_flags; |
1048 Handle<Object> holder = | 1047 Handle<Object> holder = |
1049 context->Lookup(name, flags, &index, &attributes, &binding_flags); | 1048 context->Lookup(name, flags, &index, &attributes, &binding_flags); |
1050 if (holder.is_null()) { | 1049 if (holder.is_null()) { |
1051 // In case of JSProxy, an exception might have been thrown. | 1050 // In case of JSProxy, an exception might have been thrown. |
1052 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 1051 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
1053 } | 1052 } |
1054 | 1053 |
1055 // The property was found in a context slot. | 1054 // The property was found in a context slot. |
1056 if (index >= 0) { | 1055 if (index != Context::kNotFound) { |
1057 if ((binding_flags == MUTABLE_CHECK_INITIALIZED || | 1056 if ((binding_flags == MUTABLE_CHECK_INITIALIZED || |
1058 binding_flags == IMMUTABLE_CHECK_INITIALIZED_HARMONY) && | 1057 binding_flags == IMMUTABLE_CHECK_INITIALIZED_HARMONY) && |
1059 Handle<Context>::cast(holder)->is_the_hole(index)) { | 1058 Handle<Context>::cast(holder)->is_the_hole(index)) { |
1060 THROW_NEW_ERROR_RETURN_FAILURE( | 1059 THROW_NEW_ERROR_RETURN_FAILURE( |
1061 isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); | 1060 isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); |
1062 } | 1061 } |
1063 if ((attributes & READ_ONLY) == 0) { | 1062 if ((attributes & READ_ONLY) == 0) { |
1064 Handle<Context>::cast(holder)->set(index, *value); | 1063 Handle<Context>::cast(holder)->set(index, *value); |
1065 } else if (is_strict(language_mode)) { | 1064 } else if (is_strict(language_mode)) { |
1066 // Setting read only property in strict mode. | 1065 // Setting read only property in strict mode. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1171 |
1173 // Lookup in the initial Object.prototype object. | 1172 // Lookup in the initial Object.prototype object. |
1174 Handle<Object> result; | 1173 Handle<Object> result; |
1175 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1174 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1176 isolate, result, | 1175 isolate, result, |
1177 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1176 Object::GetProperty(isolate->initial_object_prototype(), key)); |
1178 return *result; | 1177 return *result; |
1179 } | 1178 } |
1180 } // namespace internal | 1179 } // namespace internal |
1181 } // namespace v8 | 1180 } // namespace v8 |
OLD | NEW |