Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: src/handles.cc

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/global-handles.cc ('k') | src/mksnapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 CALL_HEAP_FUNCTION(obj->GetIsolate(), obj->DefineAccessor(*info), Object); 343 CALL_HEAP_FUNCTION(obj->GetIsolate(), obj->DefineAccessor(*info), Object);
344 } 344 }
345 345
346 346
347 // Wrappers for scripts are kept alive and cached in weak global 347 // Wrappers for scripts are kept alive and cached in weak global
348 // handles referred from foreign objects held by the scripts as long as 348 // handles referred from foreign objects held by the scripts as long as
349 // they are used. When they are not used anymore, the garbage 349 // they are used. When they are not used anymore, the garbage
350 // collector will call the weak callback on the global handle 350 // collector will call the weak callback on the global handle
351 // associated with the wrapper and get rid of both the wrapper and the 351 // associated with the wrapper and get rid of both the wrapper and the
352 // handle. 352 // handle.
353 static void ClearWrapperCache(Persistent<v8::Value> handle, void*) { 353 static void ClearWrapperCache(v8::Isolate* v8_isolate,
354 Persistent<v8::Value> handle,
355 void*) {
354 Handle<Object> cache = Utils::OpenHandle(*handle); 356 Handle<Object> cache = Utils::OpenHandle(*handle);
355 JSValue* wrapper = JSValue::cast(*cache); 357 JSValue* wrapper = JSValue::cast(*cache);
356 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); 358 Foreign* foreign = Script::cast(wrapper->value())->wrapper();
357 ASSERT(foreign->foreign_address() == 359 ASSERT(foreign->foreign_address() ==
358 reinterpret_cast<Address>(cache.location())); 360 reinterpret_cast<Address>(cache.location()));
359 foreign->set_foreign_address(0); 361 foreign->set_foreign_address(0);
360 Isolate* isolate = Isolate::Current(); 362 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
361 isolate->global_handles()->Destroy(cache.location()); 363 isolate->global_handles()->Destroy(cache.location());
362 isolate->counters()->script_wrappers()->Decrement(); 364 isolate->counters()->script_wrappers()->Decrement();
363 } 365 }
364 366
365 367
366 Handle<JSValue> GetScriptWrapper(Handle<Script> script) { 368 Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
367 if (script->wrapper()->foreign_address() != NULL) { 369 if (script->wrapper()->foreign_address() != NULL) {
368 // Return the script wrapper directly from the cache. 370 // Return the script wrapper directly from the cache.
369 return Handle<JSValue>( 371 return Handle<JSValue>(
370 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); 372 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
(...skipping 12 matching lines...) Expand all
383 return Handle<JSValue>( 385 return Handle<JSValue>(
384 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); 386 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
385 } 387 }
386 388
387 result->set_value(*script); 389 result->set_value(*script);
388 390
389 // Create a new weak global handle and use it to cache the wrapper 391 // Create a new weak global handle and use it to cache the wrapper
390 // for future use. The cache will automatically be cleared by the 392 // for future use. The cache will automatically be cleared by the
391 // garbage collector when it is not used anymore. 393 // garbage collector when it is not used anymore.
392 Handle<Object> handle = isolate->global_handles()->Create(*result); 394 Handle<Object> handle = isolate->global_handles()->Create(*result);
393 isolate->global_handles()->MakeWeak(handle.location(), NULL, 395 isolate->global_handles()->MakeWeak(handle.location(),
396 NULL,
397 NULL,
394 &ClearWrapperCache); 398 &ClearWrapperCache);
395 script->wrapper()->set_foreign_address( 399 script->wrapper()->set_foreign_address(
396 reinterpret_cast<Address>(handle.location())); 400 reinterpret_cast<Address>(handle.location()));
397 return result; 401 return result;
398 } 402 }
399 403
400 404
401 // Init line_ends array with code positions of line ends inside script 405 // Init line_ends array with code positions of line ends inside script
402 // source. 406 // source.
403 void InitScriptLineEnds(Handle<Script> script) { 407 void InitScriptLineEnds(Handle<Script> script) {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 data->next = prev_next_; 932 data->next = prev_next_;
929 data->limit = prev_limit_; 933 data->limit = prev_limit_;
930 #ifdef DEBUG 934 #ifdef DEBUG
931 handles_detached_ = true; 935 handles_detached_ = true;
932 #endif 936 #endif
933 return deferred; 937 return deferred;
934 } 938 }
935 939
936 940
937 } } // namespace v8::internal 941 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/global-handles.cc ('k') | src/mksnapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698