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/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Conservative upper limit to prevent fuzz tests from going OOM. | 267 // Conservative upper limit to prevent fuzz tests from going OOM. |
268 RUNTIME_ASSERT(properties <= 100000); | 268 RUNTIME_ASSERT(properties <= 100000); |
269 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { | 269 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { |
270 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, | 270 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, |
271 "OptimizeForAdding"); | 271 "OptimizeForAdding"); |
272 } | 272 } |
273 return *object; | 273 return *object; |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { | |
278 HandleScope scope(isolate); | |
279 DCHECK_EQ(1, args.length()); | |
280 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
281 | |
282 // Go up context chain to the script context. | |
283 Handle<Context> script_context(isolate->context()->script_context(), isolate); | |
284 DCHECK(script_context->IsScriptContext()); | |
285 DCHECK(script_context->get(slot)->IsPropertyCell()); | |
286 | |
287 // Lookup the named property on the global object. | |
288 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); | |
289 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | |
290 Handle<JSGlobalObject> global_object(script_context->global_object(), | |
291 isolate); | |
292 LookupIterator it(global_object, name, global_object, LookupIterator::OWN); | |
293 | |
294 // Switch to fast mode only if there is a data property and it's not on | |
295 // a hidden prototype. | |
296 if (it.state() == LookupIterator::DATA && | |
297 it.GetHolder<Object>().is_identical_to(global_object)) { | |
298 // Now update the cell in the script context. | |
299 Handle<PropertyCell> cell = it.GetPropertyCell(); | |
300 script_context->set(slot, *cell); | |
301 } else { | |
302 // This is not a fast case, so keep this access in a slow mode. | |
303 // Store empty_property_cell here to release the outdated property cell. | |
304 script_context->set(slot, isolate->heap()->empty_property_cell()); | |
305 } | |
306 | |
307 RETURN_RESULT_OR_FAILURE(isolate, Object::GetProperty(&it)); | |
308 } | |
309 | |
310 | |
311 namespace { | 277 namespace { |
312 | 278 |
313 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Object> value, | 279 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Object> value, |
314 LanguageMode language_mode) { | 280 LanguageMode language_mode) { |
315 // Go up context chain to the script context. | 281 // Go up context chain to the script context. |
316 Handle<Context> script_context(isolate->context()->script_context(), isolate); | 282 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
317 DCHECK(script_context->IsScriptContext()); | 283 DCHECK(script_context->IsScriptContext()); |
318 DCHECK(script_context->get(slot)->IsPropertyCell()); | 284 DCHECK(script_context->get(slot)->IsPropertyCell()); |
319 | 285 |
320 // Lookup the named property on the global object. | 286 // Lookup the named property on the global object. |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 isolate, o, key, &success, LookupIterator::OWN); | 970 isolate, o, key, &success, LookupIterator::OWN); |
1005 if (!success) return isolate->heap()->exception(); | 971 if (!success) return isolate->heap()->exception(); |
1006 MAYBE_RETURN( | 972 MAYBE_RETURN( |
1007 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 973 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
1008 isolate->heap()->exception()); | 974 isolate->heap()->exception()); |
1009 return *value; | 975 return *value; |
1010 } | 976 } |
1011 | 977 |
1012 } // namespace internal | 978 } // namespace internal |
1013 } // namespace v8 | 979 } // namespace v8 |
OLD | NEW |