| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 obj->SetPrototype(*value, skip_hidden_prototypes), Object); | 415 obj->SetPrototype(*value, skip_hidden_prototypes), Object); |
| 416 } | 416 } |
| 417 | 417 |
| 418 | 418 |
| 419 Handle<Object> PreventExtensions(Handle<JSObject> object) { | 419 Handle<Object> PreventExtensions(Handle<JSObject> object) { |
| 420 CALL_HEAP_FUNCTION(object->GetIsolate(), object->PreventExtensions(), Object); | 420 CALL_HEAP_FUNCTION(object->GetIsolate(), object->PreventExtensions(), Object); |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 Handle<Object> GetHiddenProperties(Handle<JSObject> obj, | 424 Handle<Object> GetHiddenProperties(Handle<JSObject> obj, |
| 425 bool create_if_needed) { | 425 JSObject::HiddenPropertiesFlag flag) { |
| 426 Isolate* isolate = obj->GetIsolate(); | 426 CALL_HEAP_FUNCTION(obj->GetIsolate(), |
| 427 Object* holder = obj->BypassGlobalProxy(); | 427 obj->GetHiddenProperties(flag), |
| 428 if (holder->IsUndefined()) return isolate->factory()->undefined_value(); | 428 Object); |
| 429 obj = Handle<JSObject>(JSObject::cast(holder), isolate); | |
| 430 | |
| 431 if (obj->HasFastProperties()) { | |
| 432 // If the object has fast properties, check whether the first slot | |
| 433 // in the descriptor array matches the hidden symbol. Since the | |
| 434 // hidden symbols hash code is zero (and no other string has hash | |
| 435 // code zero) it will always occupy the first entry if present. | |
| 436 DescriptorArray* descriptors = obj->map()->instance_descriptors(); | |
| 437 if ((descriptors->number_of_descriptors() > 0) && | |
| 438 (descriptors->GetKey(0) == isolate->heap()->hidden_symbol()) && | |
| 439 descriptors->IsProperty(0)) { | |
| 440 ASSERT(descriptors->GetType(0) == FIELD); | |
| 441 return Handle<Object>(obj->FastPropertyAt(descriptors->GetFieldIndex(0)), | |
| 442 isolate); | |
| 443 } | |
| 444 } | |
| 445 | |
| 446 // Only attempt to find the hidden properties in the local object and not | |
| 447 // in the prototype chain. Note that HasLocalProperty() can cause a GC in | |
| 448 // the general case in the presence of interceptors. | |
| 449 if (!obj->HasHiddenPropertiesObject()) { | |
| 450 // Hidden properties object not found. Allocate a new hidden properties | |
| 451 // object if requested. Otherwise return the undefined value. | |
| 452 if (create_if_needed) { | |
| 453 Handle<Object> hidden_obj = | |
| 454 isolate->factory()->NewJSObject(isolate->object_function()); | |
| 455 CALL_HEAP_FUNCTION(isolate, | |
| 456 obj->SetHiddenPropertiesObject(*hidden_obj), Object); | |
| 457 } else { | |
| 458 return isolate->factory()->undefined_value(); | |
| 459 } | |
| 460 } | |
| 461 return Handle<Object>(obj->GetHiddenPropertiesObject(), isolate); | |
| 462 } | 429 } |
| 463 | 430 |
| 464 | 431 |
| 432 int GetIdentityHash(Handle<JSObject> obj) { |
| 433 CALL_AND_RETRY(obj->GetIsolate(), |
| 434 obj->GetIdentityHash(JSObject::ALLOW_CREATION), |
| 435 return Smi::cast(__object__)->value(), |
| 436 return 0); |
| 437 } |
| 438 |
| 439 |
| 465 Handle<Object> DeleteElement(Handle<JSObject> obj, | 440 Handle<Object> DeleteElement(Handle<JSObject> obj, |
| 466 uint32_t index) { | 441 uint32_t index) { |
| 467 CALL_HEAP_FUNCTION(obj->GetIsolate(), | 442 CALL_HEAP_FUNCTION(obj->GetIsolate(), |
| 468 obj->DeleteElement(index, JSObject::NORMAL_DELETION), | 443 obj->DeleteElement(index, JSObject::NORMAL_DELETION), |
| 469 Object); | 444 Object); |
| 470 } | 445 } |
| 471 | 446 |
| 472 | 447 |
| 473 Handle<Object> DeleteProperty(Handle<JSObject> obj, | 448 Handle<Object> DeleteProperty(Handle<JSObject> obj, |
| 474 Handle<String> prop) { | 449 Handle<String> prop) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 511 } |
| 537 | 512 |
| 538 | 513 |
| 539 // Wrappers for scripts are kept alive and cached in weak global | 514 // Wrappers for scripts are kept alive and cached in weak global |
| 540 // handles referred from foreign objects held by the scripts as long as | 515 // handles referred from foreign objects held by the scripts as long as |
| 541 // they are used. When they are not used anymore, the garbage | 516 // they are used. When they are not used anymore, the garbage |
| 542 // collector will call the weak callback on the global handle | 517 // collector will call the weak callback on the global handle |
| 543 // associated with the wrapper and get rid of both the wrapper and the | 518 // associated with the wrapper and get rid of both the wrapper and the |
| 544 // handle. | 519 // handle. |
| 545 static void ClearWrapperCache(Persistent<v8::Value> handle, void*) { | 520 static void ClearWrapperCache(Persistent<v8::Value> handle, void*) { |
| 546 #ifdef ENABLE_HEAP_PROTECTION | |
| 547 // Weak reference callbacks are called as if from outside V8. We | |
| 548 // need to reeenter to unprotect the heap. | |
| 549 VMState state(OTHER); | |
| 550 #endif | |
| 551 Handle<Object> cache = Utils::OpenHandle(*handle); | 521 Handle<Object> cache = Utils::OpenHandle(*handle); |
| 552 JSValue* wrapper = JSValue::cast(*cache); | 522 JSValue* wrapper = JSValue::cast(*cache); |
| 553 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); | 523 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); |
| 554 ASSERT(foreign->address() == reinterpret_cast<Address>(cache.location())); | 524 ASSERT(foreign->address() == reinterpret_cast<Address>(cache.location())); |
| 555 foreign->set_address(0); | 525 foreign->set_address(0); |
| 556 Isolate* isolate = Isolate::Current(); | 526 Isolate* isolate = Isolate::Current(); |
| 557 isolate->global_handles()->Destroy(cache.location()); | 527 isolate->global_handles()->Destroy(cache.location()); |
| 558 isolate->counters()->script_wrappers()->Decrement(); | 528 isolate->counters()->script_wrappers()->Decrement(); |
| 559 } | 529 } |
| 560 | 530 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 } else { | 876 } else { |
| 907 int num_enum = object->NumberOfEnumProperties(); | 877 int num_enum = object->NumberOfEnumProperties(); |
| 908 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 878 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); |
| 909 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); | 879 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); |
| 910 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); | 880 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); |
| 911 return storage; | 881 return storage; |
| 912 } | 882 } |
| 913 } | 883 } |
| 914 | 884 |
| 915 | 885 |
| 886 Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table, |
| 887 Handle<JSObject> key, |
| 888 Handle<Object> value) { |
| 889 CALL_HEAP_FUNCTION(table->GetIsolate(), |
| 890 table->Put(*key, *value), |
| 891 ObjectHashTable); |
| 892 } |
| 893 |
| 894 |
| 916 bool EnsureCompiled(Handle<SharedFunctionInfo> shared, | 895 bool EnsureCompiled(Handle<SharedFunctionInfo> shared, |
| 917 ClearExceptionFlag flag) { | 896 ClearExceptionFlag flag) { |
| 918 return shared->is_compiled() || CompileLazyShared(shared, flag); | 897 return shared->is_compiled() || CompileLazyShared(shared, flag); |
| 919 } | 898 } |
| 920 | 899 |
| 921 | 900 |
| 922 static bool CompileLazyHelper(CompilationInfo* info, | 901 static bool CompileLazyHelper(CompilationInfo* info, |
| 923 ClearExceptionFlag flag) { | 902 ClearExceptionFlag flag) { |
| 924 // Compile the source information to a code object. | 903 // Compile the source information to a code object. |
| 925 ASSERT(info->IsOptimizing() || !info->shared_info()->is_compiled()); | 904 ASSERT(info->IsOptimizing() || !info->shared_info()->is_compiled()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 950 |
| 972 bool CompileOptimized(Handle<JSFunction> function, | 951 bool CompileOptimized(Handle<JSFunction> function, |
| 973 int osr_ast_id, | 952 int osr_ast_id, |
| 974 ClearExceptionFlag flag) { | 953 ClearExceptionFlag flag) { |
| 975 CompilationInfo info(function); | 954 CompilationInfo info(function); |
| 976 info.SetOptimizing(osr_ast_id); | 955 info.SetOptimizing(osr_ast_id); |
| 977 return CompileLazyHelper(&info, flag); | 956 return CompileLazyHelper(&info, flag); |
| 978 } | 957 } |
| 979 | 958 |
| 980 } } // namespace v8::internal | 959 } } // namespace v8::internal |
| OLD | NEW |