OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2979 resource, | 2979 resource, |
2980 &DisposeExternalString); | 2980 &DisposeExternalString); |
2981 return Utils::ToLocal(result); | 2981 return Utils::ToLocal(result); |
2982 } | 2982 } |
2983 | 2983 |
2984 | 2984 |
2985 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 2985 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
2986 if (IsDeadCheck("v8::String::MakeExternal()")) return false; | 2986 if (IsDeadCheck("v8::String::MakeExternal()")) return false; |
2987 if (this->IsExternal()) return false; // Already an external string. | 2987 if (this->IsExternal()) return false; // Already an external string. |
2988 ENTER_V8; | 2988 ENTER_V8; |
2989 i::Handle <i::String> obj = Utils::OpenHandle(this); | 2989 i::Handle<i::String> obj = Utils::OpenHandle(this); |
2990 bool result = obj->MakeExternal(resource); | 2990 bool result = obj->MakeExternal(resource); |
2991 if (result && !obj->IsSymbol()) { | 2991 if (result && !obj->IsSymbol()) { |
2992 // Operation was successful and the string is not a symbol. In this case | 2992 // Operation was successful and the string is not a symbol. In this case |
2993 // we need to make sure that the we call the destructor for the external | 2993 // we need to make sure that the we call the destructor for the external |
2994 // resource when no strong references to the string remain. | 2994 // resource when no strong references to the string remain. |
2995 i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj); | 2995 i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj); |
2996 i::GlobalHandles::MakeWeak(handle.location(), | 2996 i::GlobalHandles::MakeWeak(handle.location(), |
2997 resource, | 2997 resource, |
2998 &DisposeExternalString); | 2998 &DisposeExternalString); |
2999 } | 2999 } |
(...skipping 15 matching lines...) Expand all Loading... |
3015 &DisposeExternalAsciiString); | 3015 &DisposeExternalAsciiString); |
3016 return Utils::ToLocal(result); | 3016 return Utils::ToLocal(result); |
3017 } | 3017 } |
3018 | 3018 |
3019 | 3019 |
3020 bool v8::String::MakeExternal( | 3020 bool v8::String::MakeExternal( |
3021 v8::String::ExternalAsciiStringResource* resource) { | 3021 v8::String::ExternalAsciiStringResource* resource) { |
3022 if (IsDeadCheck("v8::String::MakeExternal()")) return false; | 3022 if (IsDeadCheck("v8::String::MakeExternal()")) return false; |
3023 if (this->IsExternal()) return false; // Already an external string. | 3023 if (this->IsExternal()) return false; // Already an external string. |
3024 ENTER_V8; | 3024 ENTER_V8; |
3025 i::Handle <i::String> obj = Utils::OpenHandle(this); | 3025 i::Handle<i::String> obj = Utils::OpenHandle(this); |
3026 bool result = obj->MakeExternal(resource); | 3026 bool result = obj->MakeExternal(resource); |
3027 if (result && !obj->IsSymbol()) { | 3027 if (result && !obj->IsSymbol()) { |
3028 // Operation was successful and the string is not a symbol. In this case | 3028 // Operation was successful and the string is not a symbol. In this case |
3029 // we need to make sure that the we call the destructor for the external | 3029 // we need to make sure that the we call the destructor for the external |
3030 // resource when no strong references to the string remain. | 3030 // resource when no strong references to the string remain. |
3031 i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj); | 3031 i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj); |
3032 i::GlobalHandles::MakeWeak(handle.location(), | 3032 i::GlobalHandles::MakeWeak(handle.location(), |
3033 resource, | 3033 resource, |
3034 &DisposeExternalAsciiString); | 3034 &DisposeExternalAsciiString); |
3035 } | 3035 } |
3036 return result; | 3036 return result; |
3037 } | 3037 } |
3038 | 3038 |
3039 | 3039 |
| 3040 bool v8::String::CanMakeExternal() { |
| 3041 if (IsDeadCheck("v8::String::CanMakeExternal()")) return false; |
| 3042 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 3043 int size = obj->Size(); // Byte size of the original string. |
| 3044 return (size >= i::ExternalString::kSize) && !obj->IsExternalString(); |
| 3045 } |
| 3046 |
| 3047 |
3040 Local<v8::Object> v8::Object::New() { | 3048 Local<v8::Object> v8::Object::New() { |
3041 EnsureInitialized("v8::Object::New()"); | 3049 EnsureInitialized("v8::Object::New()"); |
3042 LOG_API("Object::New"); | 3050 LOG_API("Object::New"); |
3043 ENTER_V8; | 3051 ENTER_V8; |
3044 i::Handle<i::JSObject> obj = | 3052 i::Handle<i::JSObject> obj = |
3045 i::Factory::NewJSObject(i::Top::object_function()); | 3053 i::Factory::NewJSObject(i::Top::object_function()); |
3046 return Utils::ToLocal(obj); | 3054 return Utils::ToLocal(obj); |
3047 } | 3055 } |
3048 | 3056 |
3049 | 3057 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3638 reinterpret_cast<HandleScopeImplementer*>(storage); | 3646 reinterpret_cast<HandleScopeImplementer*>(storage); |
3639 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); | 3647 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); |
3640 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = | 3648 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = |
3641 &thread_local->handle_scope_data_; | 3649 &thread_local->handle_scope_data_; |
3642 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); | 3650 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); |
3643 | 3651 |
3644 return storage + ArchiveSpacePerThread(); | 3652 return storage + ArchiveSpacePerThread(); |
3645 } | 3653 } |
3646 | 3654 |
3647 } } // namespace v8::internal | 3655 } } // namespace v8::internal |
OLD | NEW |