@@ -3082,81 +3082,13 @@ i::Handle<i::String> NewExternalAsciiStringHandle(
30823082}
30833083
30843084
3085- static void DisposeExternalString (v8::Persistent<v8::Value> obj,
3086- void * parameter) {
3087- ENTER_V8;
3088- i::ExternalTwoByteString* str =
3089- i::ExternalTwoByteString::cast (*Utils::OpenHandle (*obj));
3090-
3091- // External symbols are deleted when they are pruned out of the symbol
3092- // table. Generally external symbols are not registered with the weak handle
3093- // callbacks unless they are upgraded to a symbol after being externalized.
3094- if (!str->IsSymbol ()) {
3095- v8::String::ExternalStringResource* resource =
3096- reinterpret_cast <v8::String::ExternalStringResource*>(parameter);
3097- if (resource != NULL ) {
3098- const int total_size =
3099- static_cast <int >(resource->length () * sizeof (*resource->data ()));
3100- i::Counters::total_external_string_memory.Decrement (total_size);
3101-
3102- // The object will continue to live in the JavaScript heap until the
3103- // handle is entirely cleaned out by the next GC. For example the
3104- // destructor for the resource below could bring it back to life again.
3105- // Which is why we make sure to not have a dangling pointer here.
3106- str->set_resource (NULL );
3107- delete resource;
3108- }
3109- }
3110-
3111- // In any case we do not need this handle any longer.
3112- obj.Dispose ();
3113- }
3114-
3115-
3116- static void DisposeExternalAsciiString (v8::Persistent<v8::Value> obj,
3117- void * parameter) {
3118- ENTER_V8;
3119- i::ExternalAsciiString* str =
3120- i::ExternalAsciiString::cast (*Utils::OpenHandle (*obj));
3121-
3122- // External symbols are deleted when they are pruned out of the symbol
3123- // table. Generally external symbols are not registered with the weak handle
3124- // callbacks unless they are upgraded to a symbol after being externalized.
3125- if (!str->IsSymbol ()) {
3126- v8::String::ExternalAsciiStringResource* resource =
3127- reinterpret_cast <v8::String::ExternalAsciiStringResource*>(parameter);
3128- if (resource != NULL ) {
3129- const int total_size =
3130- static_cast <int >(resource->length () * sizeof (*resource->data ()));
3131- i::Counters::total_external_string_memory.Decrement (total_size);
3132-
3133- // The object will continue to live in the JavaScript heap until the
3134- // handle is entirely cleaned out by the next GC. For example the
3135- // destructor for the resource below could bring it back to life again.
3136- // Which is why we make sure to not have a dangling pointer here.
3137- str->set_resource (NULL );
3138- delete resource;
3139- }
3140- }
3141-
3142- // In any case we do not need this handle any longer.
3143- obj.Dispose ();
3144- }
3145-
3146-
31473085Local<String> v8::String::NewExternal (
31483086 v8::String::ExternalStringResource* resource) {
31493087 EnsureInitialized (" v8::String::NewExternal()" );
31503088 LOG_API (" String::NewExternal" );
31513089 ENTER_V8;
3152- const int total_size =
3153- static_cast <int >(resource->length () * sizeof (*resource->data ()));
3154- i::Counters::total_external_string_memory.Increment (total_size);
31553090 i::Handle<i::String> result = NewExternalStringHandle (resource);
3156- i::Handle<i::Object> handle = i::GlobalHandles::Create (*result);
3157- i::GlobalHandles::MakeWeak (handle.location (),
3158- resource,
3159- &DisposeExternalString);
3091+ i::ExternalStringTable::AddString (*result);
31603092 return Utils::ToLocal (result);
31613093}
31623094
@@ -3168,13 +3100,7 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
31683100 i::Handle<i::String> obj = Utils::OpenHandle (this );
31693101 bool result = obj->MakeExternal (resource);
31703102 if (result && !obj->IsSymbol ()) {
3171- // Operation was successful and the string is not a symbol. In this case
3172- // we need to make sure that the we call the destructor for the external
3173- // resource when no strong references to the string remain.
3174- i::Handle<i::Object> handle = i::GlobalHandles::Create (*obj);
3175- i::GlobalHandles::MakeWeak (handle.location (),
3176- resource,
3177- &DisposeExternalString);
3103+ i::ExternalStringTable::AddString (*obj);
31783104 }
31793105 return result;
31803106}
@@ -3185,14 +3111,8 @@ Local<String> v8::String::NewExternal(
31853111 EnsureInitialized (" v8::String::NewExternal()" );
31863112 LOG_API (" String::NewExternal" );
31873113 ENTER_V8;
3188- const int total_size =
3189- static_cast <int >(resource->length () * sizeof (*resource->data ()));
3190- i::Counters::total_external_string_memory.Increment (total_size);
31913114 i::Handle<i::String> result = NewExternalAsciiStringHandle (resource);
3192- i::Handle<i::Object> handle = i::GlobalHandles::Create (*result);
3193- i::GlobalHandles::MakeWeak (handle.location (),
3194- resource,
3195- &DisposeExternalAsciiString);
3115+ i::ExternalStringTable::AddString (*result);
31963116 return Utils::ToLocal (result);
31973117}
31983118
@@ -3205,13 +3125,7 @@ bool v8::String::MakeExternal(
32053125 i::Handle<i::String> obj = Utils::OpenHandle (this );
32063126 bool result = obj->MakeExternal (resource);
32073127 if (result && !obj->IsSymbol ()) {
3208- // Operation was successful and the string is not a symbol. In this case
3209- // we need to make sure that the we call the destructor for the external
3210- // resource when no strong references to the string remain.
3211- i::Handle<i::Object> handle = i::GlobalHandles::Create (*obj);
3212- i::GlobalHandles::MakeWeak (handle.location (),
3213- resource,
3214- &DisposeExternalAsciiString);
3128+ i::ExternalStringTable::AddString (*obj);
32153129 }
32163130 return result;
32173131}
0 commit comments