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

Side by Side Diff: src/handles.cc

Issue 67273004: Fix invalid reuse of weak global handle in GetScriptWrapper. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | « no previous file | test/mjsunit/regress/regress-2988.js » ('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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 reinterpret_cast<Address>(cache.location())); 235 reinterpret_cast<Address>(cache.location()));
236 foreign->set_foreign_address(0); 236 foreign->set_foreign_address(0);
237 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 237 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
238 isolate->global_handles()->Destroy(cache.location()); 238 isolate->global_handles()->Destroy(cache.location());
239 isolate->counters()->script_wrappers()->Decrement(); 239 isolate->counters()->script_wrappers()->Decrement();
240 } 240 }
241 241
242 242
243 Handle<JSValue> GetScriptWrapper(Handle<Script> script) { 243 Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
244 if (script->wrapper()->foreign_address() != NULL) { 244 if (script->wrapper()->foreign_address() != NULL) {
245 // Return the script wrapper directly from the cache. 245 // Return a handle for the existing script wrapper from the cache.
246 return Handle<JSValue>( 246 return Handle<JSValue>(
247 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); 247 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
248 } 248 }
249 Isolate* isolate = script->GetIsolate(); 249 Isolate* isolate = script->GetIsolate();
250 // Construct a new script wrapper. 250 // Construct a new script wrapper.
251 isolate->counters()->script_wrappers()->Increment(); 251 isolate->counters()->script_wrappers()->Increment();
252 Handle<JSFunction> constructor = isolate->script_function(); 252 Handle<JSFunction> constructor = isolate->script_function();
253 Handle<JSValue> result = 253 Handle<JSValue> result =
254 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); 254 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
255 255
256 // The allocation might have triggered a GC, which could have called this 256 // The allocation might have triggered a GC, which could have called this
257 // function recursively, and a wrapper has already been created and cached. 257 // function recursively, and a wrapper has already been created and cached.
258 // In that case, simply return the cached wrapper. 258 // In that case, simply return a handle for the cached wrapper.
259 if (script->wrapper()->foreign_address() != NULL) { 259 if (script->wrapper()->foreign_address() != NULL) {
260 return Handle<JSValue>( 260 return Handle<JSValue>(
261 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); 261 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
262 } 262 }
263 263
264 result->set_value(*script); 264 result->set_value(*script);
265 265
266 // Create a new weak global handle and use it to cache the wrapper 266 // Create a new weak global handle and use it to cache the wrapper
267 // for future use. The cache will automatically be cleared by the 267 // for future use. The cache will automatically be cleared by the
268 // garbage collector when it is not used anymore. 268 // garbage collector when it is not used anymore.
269 Handle<Object> handle = isolate->global_handles()->Create(*result); 269 Handle<Object> handle = isolate->global_handles()->Create(*result);
270 isolate->global_handles()->MakeWeak(handle.location(), 270 isolate->global_handles()->MakeWeak(handle.location(),
271 NULL, 271 NULL,
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 Handle<Code> code) { 795 Handle<Code> code) {
796 heap->EnsureWeakObjectToCodeTable(); 796 heap->EnsureWeakObjectToCodeTable();
797 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); 797 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
798 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); 798 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code);
799 CALL_HEAP_FUNCTION_VOID(heap->isolate(), 799 CALL_HEAP_FUNCTION_VOID(heap->isolate(),
800 heap->AddWeakObjectToCodeDependency(*object, *dep)); 800 heap->AddWeakObjectToCodeDependency(*object, *dep));
801 } 801 }
802 802
803 803
804 } } // namespace v8::internal 804 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2988.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698