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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Conservative upper limit to prevent fuzz tests from going OOM. | 270 // Conservative upper limit to prevent fuzz tests from going OOM. |
271 if (properties > 100000) return isolate->ThrowIllegalOperation(); | 271 if (properties > 100000) return isolate->ThrowIllegalOperation(); |
272 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { | 272 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { |
273 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, | 273 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, |
274 "OptimizeForAdding"); | 274 "OptimizeForAdding"); |
275 } | 275 } |
276 return *object; | 276 return *object; |
277 } | 277 } |
278 | 278 |
279 | 279 |
280 namespace { | |
281 | |
282 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Object> value, | |
283 LanguageMode language_mode) { | |
284 // Go up context chain to the script context. | |
285 Handle<Context> script_context(isolate->context()->script_context(), isolate); | |
286 DCHECK(script_context->IsScriptContext()); | |
287 DCHECK(script_context->get(slot)->IsPropertyCell()); | |
288 | |
289 // Lookup the named property on the global object. | |
290 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); | |
291 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | |
292 Handle<JSGlobalObject> global_object(script_context->global_object(), | |
293 isolate); | |
294 LookupIterator it(global_object, name, global_object, LookupIterator::OWN); | |
295 | |
296 // Switch to fast mode only if there is a data property and it's not on | |
297 // a hidden prototype. | |
298 if (it.state() == LookupIterator::DATA && | |
299 it.GetHolder<Object>().is_identical_to(global_object)) { | |
300 // Now update cell in the script context. | |
301 Handle<PropertyCell> cell = it.GetPropertyCell(); | |
302 script_context->set(slot, *cell); | |
303 } else { | |
304 // This is not a fast case, so keep this access in a slow mode. | |
305 // Store empty_property_cell here to release the outdated property cell. | |
306 script_context->set(slot, isolate->heap()->empty_property_cell()); | |
307 } | |
308 | |
309 MAYBE_RETURN(Object::SetProperty(&it, value, language_mode, | |
310 Object::CERTAINLY_NOT_STORE_FROM_KEYED), | |
311 isolate->heap()->exception()); | |
312 return *value; | |
313 } | |
314 | |
315 } // namespace | |
316 | |
317 | |
318 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Sloppy) { | |
319 HandleScope scope(isolate); | |
320 DCHECK_EQ(2, args.length()); | |
321 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
322 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | |
323 | |
324 return StoreGlobalViaContext(isolate, slot, value, SLOPPY); | |
325 } | |
326 | |
327 | |
328 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Strict) { | |
329 HandleScope scope(isolate); | |
330 DCHECK_EQ(2, args.length()); | |
331 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
332 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | |
333 | |
334 return StoreGlobalViaContext(isolate, slot, value, STRICT); | |
335 } | |
336 | |
337 | |
338 RUNTIME_FUNCTION(Runtime_GetProperty) { | 280 RUNTIME_FUNCTION(Runtime_GetProperty) { |
339 HandleScope scope(isolate); | 281 HandleScope scope(isolate); |
340 DCHECK(args.length() == 2); | 282 DCHECK(args.length() == 2); |
341 | 283 |
342 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 284 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
343 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 285 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
344 | 286 |
345 RETURN_RESULT_OR_FAILURE(isolate, | 287 RETURN_RESULT_OR_FAILURE(isolate, |
346 Runtime::GetObjectProperty(isolate, object, key)); | 288 Runtime::GetObjectProperty(isolate, object, key)); |
347 } | 289 } |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 DCHECK(args.length() == 2); | 932 DCHECK(args.length() == 2); |
991 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 933 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
992 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 934 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
993 Handle<Module> module(isolate->context()->module()); | 935 Handle<Module> module(isolate->context()->module()); |
994 Module::StoreExport(module, name, value); | 936 Module::StoreExport(module, name, value); |
995 return isolate->heap()->undefined_value(); | 937 return isolate->heap()->undefined_value(); |
996 } | 938 } |
997 | 939 |
998 } // namespace internal | 940 } // namespace internal |
999 } // namespace v8 | 941 } // namespace v8 |
OLD | NEW |