Changeset 171564 in webkit
- Timestamp:
- Jul 24, 2014, 5:59:10 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSWrapperMap.mm
r171553 r171564 465 465 } 466 466 } else { 467 // We need to hold a reference to the superclass prototype here on the stack 468 // to that it won't get GC'ed while we do allocations between now and when we 469 // set it in this class' prototype below. 470 JSC::JSObject* superClassPrototype = superClassInfo->m_prototype.get(); 471 467 472 const char* className = class_getName(m_class); 468 473 … … 494 499 495 500 // Set [Prototype]. 496 JSObjectSetPrototype([m_context JSGlobalContextRef], toRef(m_prototype.get()), toRef(superClass Info->m_prototype.get()));501 JSObjectSetPrototype([m_context JSGlobalContextRef], toRef(m_prototype.get()), toRef(superClassPrototype)); 497 502 } 498 503 } … … 501 506 { 502 507 [self allocateConstructorAndPrototypeWithSuperClassInfo:[m_context.wrapperMap classInfoForClass:class_getSuperclass(m_class)]]; 508 // We should not add any code here that can trigger a GC or the prototype and 509 // constructor that we just created may be collected before they can be used. 503 510 } 504 511 … … 520 527 [self reallocateConstructorAndOrPrototype]; 521 528 ASSERT(!!m_prototype); 529 // We need to hold a reference to the prototype here on the stack to that it won't 530 // get GC'ed while we create the wrapper below. 531 JSC::JSObject* prototype = m_prototype.get(); 522 532 523 533 JSObjectRef wrapper = makeWrapper([m_context JSGlobalContextRef], m_classRef, object); 524 JSObjectSetPrototype([m_context JSGlobalContextRef], wrapper, toRef( m_prototype.get()));534 JSObjectSetPrototype([m_context JSGlobalContextRef], wrapper, toRef(prototype)); 525 535 return [JSValue valueWithJSValueRef:wrapper inContext:m_context]; 526 536 } … … 531 541 [self reallocateConstructorAndOrPrototype]; 532 542 ASSERT(!!m_constructor); 543 // If we need to add any code here in the future that can trigger a GC, we should 544 // cache the constructor pointer in a stack local var first so that it is protected 545 // from the GC until it gets used below. 533 546 return [JSValue valueWithJSValueRef:toRef(m_constructor.get()) inContext:m_context]; 534 547 } -
trunk/Source/JavaScriptCore/ChangeLog
r171558 r171564 1 2014-07-24 Mark Lam <mark.lam@apple.com> 2 3 JSWrapperMap's jsWrapperForObject() needs to keep weak prototype and constructors from being GCed. 4 <https://webkit.org/b/135258> 5 6 Reviewed by Mark Hahnenberg. 7 8 Where needed, we cache the prototype object pointer in a stack local var. 9 This allows it to be scanned by the GC, and hence be kept alive until 10 we use it. The constructor object will in turn be kept alive by the 11 prototype object. 12 13 Also added some comments to warn against future code additions that could 14 regress this issue. 15 16 * API/JSWrapperMap.mm: 17 (-[JSObjCClassInfo allocateConstructorAndPrototypeWithSuperClassInfo:]): 18 (-[JSObjCClassInfo reallocateConstructorAndOrPrototype]): 19 (-[JSObjCClassInfo wrapperForObject:]): 20 (-[JSObjCClassInfo constructor]): 21 1 22 2014-07-24 Joseph Pecoraro <pecoraro@apple.com> 2 23
Note:
See TracChangeset
for help on using the changeset viewer.