| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2260 Handle<Object> result = JSReceiver::SetProperty( | 2260 Handle<Object> result = JSReceiver::SetProperty( |
| 2261 global, name, value, attributes, strict_mode_flag); | 2261 global, name, value, attributes, strict_mode_flag); |
| 2262 RETURN_IF_EMPTY_HANDLE(isolate, result); | 2262 RETURN_IF_EMPTY_HANDLE(isolate, result); |
| 2263 return *result; | 2263 return *result; |
| 2264 } | 2264 } |
| 2265 return isolate->heap()->undefined_value(); | 2265 return isolate->heap()->undefined_value(); |
| 2266 } | 2266 } |
| 2267 | 2267 |
| 2268 | 2268 |
| 2269 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { | 2269 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { |
| 2270 SealHandleScope shs(isolate); | 2270 HandleScope scope(isolate); |
| 2271 // All constants are declared with an initial value. The name | 2271 // All constants are declared with an initial value. The name |
| 2272 // of the constant is the first argument and the initial value | 2272 // of the constant is the first argument and the initial value |
| 2273 // is the second. | 2273 // is the second. |
| 2274 RUNTIME_ASSERT(args.length() == 2); | 2274 RUNTIME_ASSERT(args.length() == 2); |
| 2275 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 2275 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 2276 Handle<Object> value = args.at<Object>(1); | 2276 Handle<Object> value = args.at<Object>(1); |
| 2277 | 2277 |
| 2278 // Get the current global object from top. | 2278 // Get the current global object from top. |
| 2279 GlobalObject* global = isolate->context()->global_object(); | 2279 Handle<JSObject> global(isolate->context()->global_object(), isolate); |
| 2280 | 2280 |
| 2281 // According to ECMA-262, section 12.2, page 62, the property must | 2281 // According to ECMA-262, section 12.2, page 62, the property must |
| 2282 // not be deletable. Since it's a const, it must be READ_ONLY too. | 2282 // not be deletable. Since it's a const, it must be READ_ONLY too. |
| 2283 PropertyAttributes attributes = | 2283 PropertyAttributes attributes = |
| 2284 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 2284 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
| 2285 | 2285 |
| 2286 // Lookup the property locally in the global object. If it isn't | 2286 // Lookup the property locally in the global object. If it isn't |
| 2287 // there, we add the property and take special precautions to always | 2287 // there, we add the property and take special precautions to always |
| 2288 // add it as a local property even in case of callbacks in the | 2288 // add it as a local property even in case of callbacks in the |
| 2289 // prototype chain (this rules out using SetProperty). | 2289 // prototype chain (this rules out using SetProperty). |
| 2290 // We use SetLocalPropertyIgnoreAttributes instead | 2290 // We use SetLocalPropertyIgnoreAttributes instead |
| 2291 LookupResult lookup(isolate); | 2291 LookupResult lookup(isolate); |
| 2292 global->LocalLookup(*name, &lookup); | 2292 global->LocalLookup(*name, &lookup); |
| 2293 if (!lookup.IsFound()) { | 2293 if (!lookup.IsFound()) { |
| 2294 HandleScope handle_scope(isolate); | |
| 2295 Handle<GlobalObject> global(isolate->context()->global_object()); | |
| 2296 RETURN_IF_EMPTY_HANDLE( | 2294 RETURN_IF_EMPTY_HANDLE( |
| 2297 isolate, | 2295 isolate, |
| 2298 JSObject::SetLocalPropertyIgnoreAttributes(global, name, value, | 2296 JSObject::SetLocalPropertyIgnoreAttributes(global, name, value, |
| 2299 attributes)); | 2297 attributes)); |
| 2300 return *value; | 2298 return *value; |
| 2301 } | 2299 } |
| 2302 | 2300 |
| 2303 if (!lookup.IsReadOnly()) { | 2301 if (!lookup.IsReadOnly()) { |
| 2304 // Restore global object from context (in case of GC) and continue | 2302 // Restore global object from context (in case of GC) and continue |
| 2305 // with setting the value. | 2303 // with setting the value. |
| 2306 HandleScope handle_scope(isolate); | |
| 2307 Handle<GlobalObject> global(isolate->context()->global_object()); | |
| 2308 | 2304 |
| 2309 // BUG 1213575: Handle the case where we have to set a read-only | 2305 // BUG 1213575: Handle the case where we have to set a read-only |
| 2310 // property through an interceptor and only do it if it's | 2306 // property through an interceptor and only do it if it's |
| 2311 // uninitialized, e.g. the hole. Nirk... | 2307 // uninitialized, e.g. the hole. Nirk... |
| 2312 // Passing non-strict mode because the property is writable. | 2308 // Passing non-strict mode because the property is writable. |
| 2313 RETURN_IF_EMPTY_HANDLE( | 2309 RETURN_IF_EMPTY_HANDLE( |
| 2314 isolate, | 2310 isolate, |
| 2315 JSReceiver::SetProperty(global, name, value, attributes, | 2311 JSReceiver::SetProperty(global, name, value, attributes, |
| 2316 kNonStrictMode)); | 2312 kNonStrictMode)); |
| 2317 return *value; | 2313 return *value; |
| 2318 } | 2314 } |
| 2319 | 2315 |
| 2320 // Set the value, but only if we're assigning the initial value to a | 2316 // Set the value, but only if we're assigning the initial value to a |
| 2321 // constant. For now, we determine this by checking if the | 2317 // constant. For now, we determine this by checking if the |
| 2322 // current value is the hole. | 2318 // current value is the hole. |
| 2323 // Strict mode handling not needed (const is disallowed in strict mode). | 2319 // Strict mode handling not needed (const is disallowed in strict mode). |
| 2324 if (lookup.IsField()) { | 2320 if (lookup.IsField()) { |
| 2325 FixedArray* properties = global->properties(); | 2321 Handle<FixedArray> properties(global->properties(), isolate); |
| 2326 int index = lookup.GetFieldIndex().field_index(); | 2322 int index = lookup.GetFieldIndex().field_index(); |
| 2327 if (properties->get(index)->IsTheHole() || !lookup.IsReadOnly()) { | 2323 if (properties->get(index)->IsTheHole() || !lookup.IsReadOnly()) { |
| 2328 properties->set(index, *value); | 2324 properties->set(index, *value); |
| 2329 } | 2325 } |
| 2330 } else if (lookup.IsNormal()) { | 2326 } else if (lookup.IsNormal()) { |
| 2331 if (global->GetNormalizedProperty(&lookup)->IsTheHole() || | 2327 if (JSObject::GetNormalizedProperty(global, &lookup)->IsTheHole() || |
| 2332 !lookup.IsReadOnly()) { | 2328 !lookup.IsReadOnly()) { |
| 2333 HandleScope scope(isolate); | 2329 JSObject::SetNormalizedProperty(global, &lookup, value); |
| 2334 JSObject::SetNormalizedProperty(Handle<JSObject>(global), &lookup, value); | |
| 2335 } | 2330 } |
| 2336 } else { | 2331 } else { |
| 2337 // Ignore re-initialization of constants that have already been | 2332 // Ignore re-initialization of constants that have already been |
| 2338 // assigned a constant value. | 2333 // assigned a constant value. |
| 2339 ASSERT(lookup.IsReadOnly() && lookup.IsConstant()); | 2334 ASSERT(lookup.IsReadOnly() && lookup.IsConstant()); |
| 2340 } | 2335 } |
| 2341 | 2336 |
| 2342 // Use the set value as the result of the operation. | 2337 // Use the set value as the result of the operation. |
| 2343 return *value; | 2338 return *value; |
| 2344 } | 2339 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 ASSERT(lookup.IsFound()); // the property was declared | 2407 ASSERT(lookup.IsFound()); // the property was declared |
| 2413 ASSERT(lookup.IsReadOnly()); // and it was declared as read-only | 2408 ASSERT(lookup.IsReadOnly()); // and it was declared as read-only |
| 2414 | 2409 |
| 2415 if (lookup.IsField()) { | 2410 if (lookup.IsField()) { |
| 2416 FixedArray* properties = object->properties(); | 2411 FixedArray* properties = object->properties(); |
| 2417 int index = lookup.GetFieldIndex().field_index(); | 2412 int index = lookup.GetFieldIndex().field_index(); |
| 2418 if (properties->get(index)->IsTheHole()) { | 2413 if (properties->get(index)->IsTheHole()) { |
| 2419 properties->set(index, *value); | 2414 properties->set(index, *value); |
| 2420 } | 2415 } |
| 2421 } else if (lookup.IsNormal()) { | 2416 } else if (lookup.IsNormal()) { |
| 2422 if (object->GetNormalizedProperty(&lookup)->IsTheHole()) { | 2417 if (JSObject::GetNormalizedProperty(object, &lookup)->IsTheHole()) { |
| 2423 JSObject::SetNormalizedProperty(object, &lookup, value); | 2418 JSObject::SetNormalizedProperty(object, &lookup, value); |
| 2424 } | 2419 } |
| 2425 } else { | 2420 } else { |
| 2426 // We should not reach here. Any real, named property should be | 2421 // We should not reach here. Any real, named property should be |
| 2427 // either a field or a dictionary slot. | 2422 // either a field or a dictionary slot. |
| 2428 UNREACHABLE(); | 2423 UNREACHABLE(); |
| 2429 } | 2424 } |
| 2430 } else { | 2425 } else { |
| 2431 // The property was found on some other object. Set it if it is not a | 2426 // The property was found on some other object. Set it if it is not a |
| 2432 // read-only property. | 2427 // read-only property. |
| (...skipping 2650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5083 return Runtime::ForceSetObjectProperty(isolate, | 5078 return Runtime::ForceSetObjectProperty(isolate, |
| 5084 js_object, | 5079 js_object, |
| 5085 name, | 5080 name, |
| 5086 obj_value, | 5081 obj_value, |
| 5087 attr); | 5082 attr); |
| 5088 } | 5083 } |
| 5089 | 5084 |
| 5090 | 5085 |
| 5091 // Return property without being observable by accessors or interceptors. | 5086 // Return property without being observable by accessors or interceptors. |
| 5092 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) { | 5087 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) { |
| 5093 SealHandleScope shs(isolate); | 5088 HandleScope scope(isolate); |
| 5094 ASSERT(args.length() == 2); | 5089 ASSERT(args.length() == 2); |
| 5095 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 5090 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 5096 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 5091 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 5097 LookupResult lookup(isolate); | 5092 LookupResult lookup(isolate); |
| 5098 object->LookupRealNamedProperty(*key, &lookup); | 5093 object->LookupRealNamedProperty(*key, &lookup); |
| 5099 if (!lookup.IsFound()) return isolate->heap()->undefined_value(); | 5094 if (!lookup.IsFound()) return isolate->heap()->undefined_value(); |
| 5100 switch (lookup.type()) { | 5095 switch (lookup.type()) { |
| 5101 case NORMAL: | 5096 case NORMAL: { |
| 5102 return lookup.holder()->GetNormalizedProperty(&lookup); | 5097 Handle<Object> value = |
| 5098 JSObject::GetNormalizedProperty(handle(lookup.holder()), &lookup); |
| 5099 if (value->IsTheHole()) break; |
| 5100 return *value; |
| 5101 } |
| 5103 case FIELD: | 5102 case FIELD: |
| 5104 return lookup.holder()->FastPropertyAt( | 5103 return lookup.holder()->FastPropertyAt( |
| 5105 lookup.representation(), | 5104 lookup.representation(), |
| 5106 lookup.GetFieldIndex().field_index()); | 5105 lookup.GetFieldIndex().field_index()); |
| 5107 case CONSTANT: | 5106 case CONSTANT: |
| 5108 return lookup.GetConstant(); | 5107 return lookup.GetConstant(); |
| 5109 case CALLBACKS: | 5108 case CALLBACKS: |
| 5110 case HANDLER: | 5109 case HANDLER: |
| 5111 case INTERCEPTOR: | 5110 case INTERCEPTOR: |
| 5112 case TRANSITION: | 5111 case TRANSITION: |
| (...skipping 5553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10666 } | 10665 } |
| 10667 | 10666 |
| 10668 | 10667 |
| 10669 static MaybeObject* DebugLookupResultValue(Heap* heap, | 10668 static MaybeObject* DebugLookupResultValue(Heap* heap, |
| 10670 Object* receiver, | 10669 Object* receiver, |
| 10671 Name* name, | 10670 Name* name, |
| 10672 LookupResult* result, | 10671 LookupResult* result, |
| 10673 bool* caught_exception) { | 10672 bool* caught_exception) { |
| 10674 Object* value; | 10673 Object* value; |
| 10675 switch (result->type()) { | 10674 switch (result->type()) { |
| 10676 case NORMAL: | 10675 case NORMAL: { |
| 10677 value = result->holder()->GetNormalizedProperty(result); | 10676 HandleScope scope(name->GetIsolate()); |
| 10678 if (value->IsTheHole()) { | 10677 Handle<Object> value = |
| 10679 return heap->undefined_value(); | 10678 JSObject::GetNormalizedProperty(handle(result->holder()), result); |
| 10680 } | 10679 return (value->IsTheHole()) ? heap->undefined_value() : *value; |
| 10681 return value; | 10680 } |
| 10682 case FIELD: { | 10681 case FIELD: { |
| 10683 Object* value; | 10682 Object* value; |
| 10684 MaybeObject* maybe_value = | 10683 MaybeObject* maybe_value = |
| 10685 JSObject::cast(result->holder())->FastPropertyAt( | 10684 JSObject::cast(result->holder())->FastPropertyAt( |
| 10686 result->representation(), | 10685 result->representation(), |
| 10687 result->GetFieldIndex().field_index()); | 10686 result->GetFieldIndex().field_index()); |
| 10688 if (!maybe_value->To(&value)) return maybe_value; | 10687 if (!maybe_value->To(&value)) return maybe_value; |
| 10689 if (value->IsTheHole()) { | 10688 if (value->IsTheHole()) { |
| 10690 return heap->undefined_value(); | 10689 return heap->undefined_value(); |
| 10691 } | 10690 } |
| (...skipping 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14827 // Handle last resort GC and make sure to allow future allocations | 14826 // Handle last resort GC and make sure to allow future allocations |
| 14828 // to grow the heap without causing GCs (if possible). | 14827 // to grow the heap without causing GCs (if possible). |
| 14829 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14828 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14830 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14829 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14831 "Runtime::PerformGC"); | 14830 "Runtime::PerformGC"); |
| 14832 } | 14831 } |
| 14833 } | 14832 } |
| 14834 | 14833 |
| 14835 | 14834 |
| 14836 } } // namespace v8::internal | 14835 } } // namespace v8::internal |
| OLD | NEW |