| 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/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 bool is_const, bool is_function) { | 37 bool is_const, bool is_function) { |
| 38 Handle<ScriptContextTable> script_contexts( | 38 Handle<ScriptContextTable> script_contexts( |
| 39 global->native_context()->script_context_table()); | 39 global->native_context()->script_context_table()); |
| 40 ScriptContextTable::LookupResult lookup; | 40 ScriptContextTable::LookupResult lookup; |
| 41 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && | 41 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && |
| 42 IsLexicalVariableMode(lookup.mode)) { | 42 IsLexicalVariableMode(lookup.mode)) { |
| 43 return ThrowRedeclarationError(isolate, name); | 43 return ThrowRedeclarationError(isolate, name); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Do the lookup own properties only, see ES5 erratum. | 46 // Do the lookup own properties only, see ES5 erratum. |
| 47 LookupIterator it(global, name, global, | 47 LookupIterator it(global, name, global, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 48 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | |
| 49 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 48 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 50 if (!maybe.IsJust()) return isolate->heap()->exception(); | 49 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 51 | 50 |
| 52 if (it.IsFound()) { | 51 if (it.IsFound()) { |
| 53 PropertyAttributes old_attributes = maybe.FromJust(); | 52 PropertyAttributes old_attributes = maybe.FromJust(); |
| 54 // The name was declared before; check for conflicting re-declarations. | 53 // The name was declared before; check for conflicting re-declarations. |
| 55 if (is_const) return ThrowRedeclarationError(isolate, name); | 54 if (is_const) return ThrowRedeclarationError(isolate, name); |
| 56 | 55 |
| 57 // Skip var re-declarations. | 56 // Skip var re-declarations. |
| 58 if (is_var) return isolate->heap()->undefined_value(); | 57 if (is_var) return isolate->heap()->undefined_value(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // All constants are declared with an initial value. The name | 174 // All constants are declared with an initial value. The name |
| 176 // of the constant is the first argument and the initial value | 175 // of the constant is the first argument and the initial value |
| 177 // is the second. | 176 // is the second. |
| 178 RUNTIME_ASSERT(args.length() == 2); | 177 RUNTIME_ASSERT(args.length() == 2); |
| 179 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 178 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 180 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 179 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 181 | 180 |
| 182 Handle<JSGlobalObject> global = isolate->global_object(); | 181 Handle<JSGlobalObject> global = isolate->global_object(); |
| 183 | 182 |
| 184 // Lookup the property as own on the global object. | 183 // Lookup the property as own on the global object. |
| 185 LookupIterator it(global, name, global, | 184 LookupIterator it(global, name, global, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 186 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | |
| 187 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 185 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 188 DCHECK(maybe.IsJust()); | 186 DCHECK(maybe.IsJust()); |
| 189 PropertyAttributes old_attributes = maybe.FromJust(); | 187 PropertyAttributes old_attributes = maybe.FromJust(); |
| 190 | 188 |
| 191 PropertyAttributes attr = | 189 PropertyAttributes attr = |
| 192 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 190 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
| 193 // Set the value if the property is either missing, or the property attributes | 191 // Set the value if the property is either missing, or the property attributes |
| 194 // allow setting the value without invoking an accessor. | 192 // allow setting the value without invoking an accessor. |
| 195 if (it.IsFound()) { | 193 if (it.IsFound()) { |
| 196 // Ignore if we can't reconfigure the value. | 194 // Ignore if we can't reconfigure the value. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 VariableMode mode = scope_info->ContextLocalMode(var); | 613 VariableMode mode = scope_info->ContextLocalMode(var); |
| 616 ScriptContextTable::LookupResult lookup; | 614 ScriptContextTable::LookupResult lookup; |
| 617 if (ScriptContextTable::Lookup(script_context, name, &lookup)) { | 615 if (ScriptContextTable::Lookup(script_context, name, &lookup)) { |
| 618 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { | 616 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { |
| 619 return ThrowRedeclarationError(isolate, name); | 617 return ThrowRedeclarationError(isolate, name); |
| 620 } | 618 } |
| 621 } | 619 } |
| 622 | 620 |
| 623 if (IsLexicalVariableMode(mode)) { | 621 if (IsLexicalVariableMode(mode)) { |
| 624 LookupIterator it(global_object, name, global_object, | 622 LookupIterator it(global_object, name, global_object, |
| 625 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 623 LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 626 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 624 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 627 if (!maybe.IsJust()) return isolate->heap()->exception(); | 625 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 628 if ((maybe.FromJust() & DONT_DELETE) != 0) { | 626 if ((maybe.FromJust() & DONT_DELETE) != 0) { |
| 629 return ThrowRedeclarationError(isolate, name); | 627 return ThrowRedeclarationError(isolate, name); |
| 630 } | 628 } |
| 631 | 629 |
| 632 JSGlobalObject::InvalidatePropertyCell(global_object, name); | 630 JSGlobalObject::InvalidatePropertyCell(global_object, name); |
| 633 } | 631 } |
| 634 } | 632 } |
| 635 return isolate->heap()->undefined_value(); | 633 return isolate->heap()->undefined_value(); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 DCHECK_EQ(2, args.length()); | 1032 DCHECK_EQ(2, args.length()); |
| 1035 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 1033 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 1036 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 1034 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 1037 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, | 1035 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, |
| 1038 StoreLookupSlot(name, value, STRICT)); | 1036 StoreLookupSlot(name, value, STRICT)); |
| 1039 return *value; | 1037 return *value; |
| 1040 } | 1038 } |
| 1041 | 1039 |
| 1042 } // namespace internal | 1040 } // namespace internal |
| 1043 } // namespace v8 | 1041 } // namespace v8 |
| OLD | NEW |