| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 DCHECK(is_function); | 59 DCHECK(is_function); |
| 60 if ((old_attributes & DONT_DELETE) != 0) { | 60 if ((old_attributes & DONT_DELETE) != 0) { |
| 61 // Only allow reconfiguring globals to functions in user code (no | 61 // Only allow reconfiguring globals to functions in user code (no |
| 62 // natives, which are marked as read-only). | 62 // natives, which are marked as read-only). |
| 63 DCHECK((attr & READ_ONLY) == 0); | 63 DCHECK((attr & READ_ONLY) == 0); |
| 64 | 64 |
| 65 // Check whether we can reconfigure the existing property into a | 65 // Check whether we can reconfigure the existing property into a |
| 66 // function. | 66 // function. |
| 67 PropertyDetails old_details = it.property_details(); | 67 PropertyDetails old_details = it.property_details(); |
| 68 // TODO(verwaest): ACCESSOR_CONSTANT invalidly includes | |
| 69 // ExecutableAccessInfo, | |
| 70 // which are actually data properties, not accessor properties. | |
| 71 if (old_details.IsReadOnly() || old_details.IsDontEnum() || | 68 if (old_details.IsReadOnly() || old_details.IsDontEnum() || |
| 72 old_details.type() == ACCESSOR_CONSTANT) { | 69 (it.state() == LookupIterator::ACCESSOR && |
| 70 it.GetAccessors()->IsAccessorPair())) { |
| 73 return ThrowRedeclarationError(isolate, name); | 71 return ThrowRedeclarationError(isolate, name); |
| 74 } | 72 } |
| 75 // If the existing property is not configurable, keep its attributes. Do | 73 // If the existing property is not configurable, keep its attributes. Do |
| 76 attr = old_attributes; | 74 attr = old_attributes; |
| 77 } | 75 } |
| 76 |
| 77 // If the current state is ACCESSOR, this could mean it's an AccessorInfo |
| 78 // type property. We are not allowed to call into such setters during global |
| 79 // function declaration since this would break e.g., onload. Meaning |
| 80 // 'function onload() {}' would invalidly register that function as the |
| 81 // onload callback. To avoid this situation, we first delete the property |
| 82 // before readding it as a regular data property below. |
| 83 if (it.state() == LookupIterator::ACCESSOR) it.Delete(); |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Define or redefine own property. | 86 // Define or redefine own property. |
| 81 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 87 RETURN_FAILURE_ON_EXCEPTION( |
| 82 global, name, value, attr)); | 88 isolate, JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attr)); |
| 83 | 89 |
| 84 return isolate->heap()->undefined_value(); | 90 return isolate->heap()->undefined_value(); |
| 85 } | 91 } |
| 86 | 92 |
| 87 | 93 |
| 88 RUNTIME_FUNCTION(Runtime_DeclareGlobals) { | 94 RUNTIME_FUNCTION(Runtime_DeclareGlobals) { |
| 89 HandleScope scope(isolate); | 95 HandleScope scope(isolate); |
| 90 DCHECK_EQ(2, args.length()); | 96 DCHECK_EQ(2, args.length()); |
| 91 Handle<JSGlobalObject> global(isolate->global_object()); | 97 Handle<JSGlobalObject> global(isolate->global_object()); |
| 92 Handle<Context> context(isolate->context()); | 98 Handle<Context> context(isolate->context()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // Ignore if we can't reconfigure the value. | 195 // Ignore if we can't reconfigure the value. |
| 190 if ((old_attributes & DONT_DELETE) != 0) { | 196 if ((old_attributes & DONT_DELETE) != 0) { |
| 191 if ((old_attributes & READ_ONLY) != 0 || | 197 if ((old_attributes & READ_ONLY) != 0 || |
| 192 it.state() == LookupIterator::ACCESSOR) { | 198 it.state() == LookupIterator::ACCESSOR) { |
| 193 return *value; | 199 return *value; |
| 194 } | 200 } |
| 195 attr = static_cast<PropertyAttributes>(old_attributes | READ_ONLY); | 201 attr = static_cast<PropertyAttributes>(old_attributes | READ_ONLY); |
| 196 } | 202 } |
| 197 } | 203 } |
| 198 | 204 |
| 199 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 205 RETURN_FAILURE_ON_EXCEPTION( |
| 200 global, name, value, attr)); | 206 isolate, JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attr)); |
| 201 | 207 |
| 202 return *value; | 208 return *value; |
| 203 } | 209 } |
| 204 | 210 |
| 205 | 211 |
| 206 namespace { | 212 namespace { |
| 207 | 213 |
| 208 Object* DeclareLookupSlot(Isolate* isolate, Handle<String> name, | 214 Object* DeclareLookupSlot(Isolate* isolate, Handle<String> name, |
| 209 Handle<Object> initial_value, | 215 Handle<Object> initial_value, |
| 210 PropertyAttributes attr) { | 216 PropertyAttributes attr) { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 | 1252 |
| 1247 // Lookup in the initial Object.prototype object. | 1253 // Lookup in the initial Object.prototype object. |
| 1248 Handle<Object> result; | 1254 Handle<Object> result; |
| 1249 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1255 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1250 isolate, result, | 1256 isolate, result, |
| 1251 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1257 Object::GetProperty(isolate->initial_object_prototype(), key)); |
| 1252 return *result; | 1258 return *result; |
| 1253 } | 1259 } |
| 1254 } // namespace internal | 1260 } // namespace internal |
| 1255 } // namespace v8 | 1261 } // namespace v8 |
| OLD | NEW |