| 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 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 // Get AccessorPair if present. | 1973 // Get AccessorPair if present. |
| 1974 maybe_accessors = JSObject::GetOwnElementAccessorPair(obj, index); | 1974 maybe_accessors = JSObject::GetOwnElementAccessorPair(obj, index); |
| 1975 | 1975 |
| 1976 // Get value if not an AccessorPair. | 1976 // Get value if not an AccessorPair. |
| 1977 if (maybe_accessors.is_null()) { | 1977 if (maybe_accessors.is_null()) { |
| 1978 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, | 1978 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, |
| 1979 Runtime::GetElementOrCharAt(isolate, obj, index), Object); | 1979 Runtime::GetElementOrCharAt(isolate, obj, index), Object); |
| 1980 } | 1980 } |
| 1981 } else { | 1981 } else { |
| 1982 // Get attributes. | 1982 // Get attributes. |
| 1983 LookupIterator it(obj, name, LookupIterator::CHECK_OWN); | 1983 LookupIterator it(obj, name, LookupIterator::CHECK_HIDDEN); |
| 1984 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); | 1984 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); |
| 1985 if (!maybe.has_value) return MaybeHandle<Object>(); | 1985 if (!maybe.has_value) return MaybeHandle<Object>(); |
| 1986 attrs = maybe.value; | 1986 attrs = maybe.value; |
| 1987 if (attrs == ABSENT) return factory->undefined_value(); | 1987 if (attrs == ABSENT) return factory->undefined_value(); |
| 1988 | 1988 |
| 1989 // Get AccessorPair if present. | 1989 // Get AccessorPair if present. |
| 1990 if (it.state() == LookupIterator::PROPERTY && | 1990 if (it.state() == LookupIterator::PROPERTY && |
| 1991 it.property_kind() == LookupIterator::ACCESSOR && | 1991 it.property_kind() == LookupIterator::ACCESSOR && |
| 1992 it.GetAccessors()->IsAccessorPair()) { | 1992 it.GetAccessors()->IsAccessorPair()) { |
| 1993 maybe_accessors = Handle<AccessorPair>::cast(it.GetAccessors()); | 1993 maybe_accessors = Handle<AccessorPair>::cast(it.GetAccessors()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2152 return isolate->Throw(*error); | 2152 return isolate->Throw(*error); |
| 2153 } | 2153 } |
| 2154 | 2154 |
| 2155 | 2155 |
| 2156 // May throw a RedeclarationError. | 2156 // May throw a RedeclarationError. |
| 2157 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, | 2157 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, |
| 2158 Handle<String> name, Handle<Object> value, | 2158 Handle<String> name, Handle<Object> value, |
| 2159 PropertyAttributes attr, bool is_var, | 2159 PropertyAttributes attr, bool is_var, |
| 2160 bool is_const, bool is_function) { | 2160 bool is_const, bool is_function) { |
| 2161 // Do the lookup own properties only, see ES5 erratum. | 2161 // Do the lookup own properties only, see ES5 erratum. |
| 2162 LookupIterator it(global, name, LookupIterator::CHECK_HIDDEN); | 2162 LookupIterator it(global, name, LookupIterator::CHECK_HIDDEN_PROPERTY); |
| 2163 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 2163 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 2164 DCHECK(maybe.has_value); | 2164 DCHECK(maybe.has_value); |
| 2165 PropertyAttributes old_attributes = maybe.value; | 2165 PropertyAttributes old_attributes = maybe.value; |
| 2166 | 2166 |
| 2167 if (old_attributes != ABSENT) { | 2167 if (old_attributes != ABSENT) { |
| 2168 // The name was declared before; check for conflicting re-declarations. | 2168 // The name was declared before; check for conflicting re-declarations. |
| 2169 if (is_const) return ThrowRedeclarationError(isolate, name); | 2169 if (is_const) return ThrowRedeclarationError(isolate, name); |
| 2170 | 2170 |
| 2171 // Skip var re-declarations. | 2171 // Skip var re-declarations. |
| 2172 if (is_var) return isolate->heap()->undefined_value(); | 2172 if (is_var) return isolate->heap()->undefined_value(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 // All constants are declared with an initial value. The name | 2282 // All constants are declared with an initial value. The name |
| 2283 // of the constant is the first argument and the initial value | 2283 // of the constant is the first argument and the initial value |
| 2284 // is the second. | 2284 // is the second. |
| 2285 RUNTIME_ASSERT(args.length() == 2); | 2285 RUNTIME_ASSERT(args.length() == 2); |
| 2286 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 2286 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 2287 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 2287 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 2288 | 2288 |
| 2289 Handle<GlobalObject> global = isolate->global_object(); | 2289 Handle<GlobalObject> global = isolate->global_object(); |
| 2290 | 2290 |
| 2291 // Lookup the property as own on the global object. | 2291 // Lookup the property as own on the global object. |
| 2292 LookupIterator it(global, name, LookupIterator::CHECK_HIDDEN); | 2292 LookupIterator it(global, name, LookupIterator::CHECK_HIDDEN_PROPERTY); |
| 2293 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 2293 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 2294 DCHECK(maybe.has_value); | 2294 DCHECK(maybe.has_value); |
| 2295 PropertyAttributes old_attributes = maybe.value; | 2295 PropertyAttributes old_attributes = maybe.value; |
| 2296 | 2296 |
| 2297 PropertyAttributes attr = | 2297 PropertyAttributes attr = |
| 2298 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 2298 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
| 2299 // Set the value if the property is either missing, or the property attributes | 2299 // Set the value if the property is either missing, or the property attributes |
| 2300 // allow setting the value without invoking an accessor. | 2300 // allow setting the value without invoking an accessor. |
| 2301 if (it.IsFound()) { | 2301 if (it.IsFound()) { |
| 2302 // Ignore if we can't reconfigure the value. | 2302 // Ignore if we can't reconfigure the value. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 DCHECK(context_arg->has_extension()); | 2432 DCHECK(context_arg->has_extension()); |
| 2433 if (attributes == ABSENT) { | 2433 if (attributes == ABSENT) { |
| 2434 holder = handle(context_arg->extension(), isolate); | 2434 holder = handle(context_arg->extension(), isolate); |
| 2435 } else { | 2435 } else { |
| 2436 // For JSContextExtensionObjects, the initializer can be run multiple times | 2436 // For JSContextExtensionObjects, the initializer can be run multiple times |
| 2437 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the | 2437 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the |
| 2438 // first assignment should go through. For JSGlobalObjects, additionally any | 2438 // first assignment should go through. For JSGlobalObjects, additionally any |
| 2439 // code can run in between that modifies the declared property. | 2439 // code can run in between that modifies the declared property. |
| 2440 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); | 2440 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); |
| 2441 | 2441 |
| 2442 LookupIterator it(holder, name, LookupIterator::CHECK_HIDDEN); | 2442 LookupIterator it(holder, name, LookupIterator::CHECK_HIDDEN_PROPERTY); |
| 2443 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 2443 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 2444 if (!maybe.has_value) return isolate->heap()->exception(); | 2444 if (!maybe.has_value) return isolate->heap()->exception(); |
| 2445 PropertyAttributes old_attributes = maybe.value; | 2445 PropertyAttributes old_attributes = maybe.value; |
| 2446 | 2446 |
| 2447 // Ignore if we can't reconfigure the value. | 2447 // Ignore if we can't reconfigure the value. |
| 2448 if ((old_attributes & DONT_DELETE) != 0) { | 2448 if ((old_attributes & DONT_DELETE) != 0) { |
| 2449 if ((old_attributes & READ_ONLY) != 0 || | 2449 if ((old_attributes & READ_ONLY) != 0 || |
| 2450 it.property_kind() == LookupIterator::ACCESSOR) { | 2450 it.property_kind() == LookupIterator::ACCESSOR) { |
| 2451 return *value; | 2451 return *value; |
| 2452 } | 2452 } |
| (...skipping 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5270 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); | 5270 CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); |
| 5271 RUNTIME_ASSERT( | 5271 RUNTIME_ASSERT( |
| 5272 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 5272 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 5273 // Compute attributes. | 5273 // Compute attributes. |
| 5274 PropertyAttributes attributes = | 5274 PropertyAttributes attributes = |
| 5275 static_cast<PropertyAttributes>(unchecked_attributes); | 5275 static_cast<PropertyAttributes>(unchecked_attributes); |
| 5276 | 5276 |
| 5277 #ifdef DEBUG | 5277 #ifdef DEBUG |
| 5278 uint32_t index = 0; | 5278 uint32_t index = 0; |
| 5279 DCHECK(!key->ToArrayIndex(&index)); | 5279 DCHECK(!key->ToArrayIndex(&index)); |
| 5280 LookupIterator it(object, key, LookupIterator::CHECK_OWN_REAL); | 5280 LookupIterator it(object, key, LookupIterator::CHECK_PROPERTY); |
| 5281 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 5281 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 5282 DCHECK(maybe.has_value); | 5282 DCHECK(maybe.has_value); |
| 5283 RUNTIME_ASSERT(!it.IsFound()); | 5283 RUNTIME_ASSERT(!it.IsFound()); |
| 5284 #endif | 5284 #endif |
| 5285 | 5285 |
| 5286 Handle<Object> result; | 5286 Handle<Object> result; |
| 5287 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 5287 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5288 isolate, result, | 5288 isolate, result, |
| 5289 JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attributes)); | 5289 JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attributes)); |
| 5290 return *result; | 5290 return *result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5302 RUNTIME_ASSERT( | 5302 RUNTIME_ASSERT( |
| 5303 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 5303 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 5304 // Compute attributes. | 5304 // Compute attributes. |
| 5305 PropertyAttributes attributes = | 5305 PropertyAttributes attributes = |
| 5306 static_cast<PropertyAttributes>(unchecked_attributes); | 5306 static_cast<PropertyAttributes>(unchecked_attributes); |
| 5307 | 5307 |
| 5308 #ifdef DEBUG | 5308 #ifdef DEBUG |
| 5309 bool duplicate; | 5309 bool duplicate; |
| 5310 if (key->IsName()) { | 5310 if (key->IsName()) { |
| 5311 LookupIterator it(object, Handle<Name>::cast(key), | 5311 LookupIterator it(object, Handle<Name>::cast(key), |
| 5312 LookupIterator::CHECK_OWN_REAL); | 5312 LookupIterator::CHECK_PROPERTY); |
| 5313 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 5313 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 5314 DCHECK(maybe.has_value); | 5314 DCHECK(maybe.has_value); |
| 5315 duplicate = it.IsFound(); | 5315 duplicate = it.IsFound(); |
| 5316 } else { | 5316 } else { |
| 5317 uint32_t index = 0; | 5317 uint32_t index = 0; |
| 5318 RUNTIME_ASSERT(key->ToArrayIndex(&index)); | 5318 RUNTIME_ASSERT(key->ToArrayIndex(&index)); |
| 5319 Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index); | 5319 Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index); |
| 5320 if (!maybe.has_value) return isolate->heap()->exception(); | 5320 if (!maybe.has_value) return isolate->heap()->exception(); |
| 5321 duplicate = maybe.value; | 5321 duplicate = maybe.value; |
| 5322 } | 5322 } |
| (...skipping 10299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15622 } | 15622 } |
| 15623 return NULL; | 15623 return NULL; |
| 15624 } | 15624 } |
| 15625 | 15625 |
| 15626 | 15626 |
| 15627 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15627 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15628 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15628 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15629 } | 15629 } |
| 15630 | 15630 |
| 15631 } } // namespace v8::internal | 15631 } } // namespace v8::internal |
| OLD | NEW |