Support WeakMap
Created attachment 210818 [details] Patch
Attachment 210818 [details] did not pass style-queue: Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj', u'Source/JavaScriptCore/heap/WeakImpl.h', u'Source/JavaScriptCore/heap/WeakInlines.h', u'Source/JavaScriptCore/runtime/CommonIdentifiers.h', u'Source/JavaScriptCore/runtime/JSGlobalObject.cpp', u'Source/JavaScriptCore/runtime/JSGlobalObject.h', u'Source/JavaScriptCore/runtime/JSWeakMap.cpp', u'Source/JavaScriptCore/runtime/JSWeakMap.h', u'Source/JavaScriptCore/runtime/WeakMapConstructor.cpp', u'Source/JavaScriptCore/runtime/WeakMapConstructor.h', u'Source/JavaScriptCore/runtime/WeakMapData.cpp', u'Source/JavaScriptCore/runtime/WeakMapData.h', u'Source/JavaScriptCore/runtime/WeakMapPrototype.cpp', u'Source/JavaScriptCore/runtime/WeakMapPrototype.h', u'Source/JavaScriptCore/tests/mozilla/actual.html']" exit_code: 1 Source/JavaScriptCore/runtime/WeakMapData.cpp:57: Code inside a namespace should not be indented. [whitespace/indent] [4] Source/JavaScriptCore/runtime/WeakMapData.cpp:59: Missing spaces around >> [whitespace/operators] [3] Source/JavaScriptCore/runtime/WeakMapData.cpp:69: Missing spaces around >> [whitespace/operators] [3] Source/JavaScriptCore/runtime/WeakMapData.cpp:77: Missing spaces around >> [whitespace/operators] [3] Source/JavaScriptCore/runtime/WeakMapData.cpp:87: Missing spaces around >> [whitespace/operators] [3] Source/JavaScriptCore/runtime/WeakMapData.cpp:96: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5] Source/JavaScriptCore/runtime/WeakMapConstructor.cpp:64: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5] Total errors found: 7 in 16 files If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass qt-ews (qt): Output: http://webkit-queues.appspot.com/results/1718207
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass qt-wk2-ews (qt-wk2): Output: http://webkit-queues.appspot.com/results/1705578
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/1704539
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/1708553
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass win-ews (win): Output: http://webkit-queues.appspot.com/results/1707594
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass efl-wk2-ews (efl-wk2): Output: http://webkit-queues.appspot.com/results/1709541
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass efl-ews (efl): Output: http://webkit-queues.appspot.com/results/1718242
Comment on attachment 210818 [details] Patch Attachment 210818 [details] did not pass gtk-ews (gtk): Output: http://webkit-queues.appspot.com/results/1704565
Comment on attachment 210818 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=210818&action=review > Source/JavaScriptCore/runtime/JSGlobalObject.h:204 > WriteBarrier<Structure> m_mapDataStructure; > + WriteBarrier<Structure> m_weakMapDataStructure; Does the WeakMapData object's structure need to be per-global object if it is not expose (e.g. can it be per-vm)? Same question for MapData's structure?
(In reply to comment #11) > (From update of attachment 210818 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=210818&action=review > > > Source/JavaScriptCore/runtime/JSGlobalObject.h:204 > > WriteBarrier<Structure> m_mapDataStructure; > > + WriteBarrier<Structure> m_weakMapDataStructure; > > Does the WeakMapData object's structure need to be per-global object if it is not expose (e.g. can it be per-vm)? Same question for MapData's structure? Not strictly but the destructible object is an Object and thus requires a global object :-/ I'm still working on WeakMap so was using this to move the patch around -- it's currently hideously ugly, leaks like a sieve, etc, etc :-/
Created attachment 211107 [details] Patch
Comment on attachment 211107 [details] Patch Attachment 211107 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/1736433
Comment on attachment 211107 [details] Patch Attachment 211107 [details] did not pass qt-ews (qt): Output: http://webkit-queues.appspot.com/results/1726714
Comment on attachment 211107 [details] Patch Attachment 211107 [details] did not pass qt-wk2-ews (qt-wk2): Output: http://webkit-queues.appspot.com/results/1734446
Created attachment 211112 [details] Patch
Comment on attachment 211112 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=211112&action=review > Source/JavaScriptCore/runtime/JSWeakMap.h:35 > +class JSWeakMap : public JSObject { Most of these instance classes are derived from JSNonFinalObjects.
Created attachment 211234 [details] Patch
Comment on attachment 211234 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=211234&action=review r=me > Source/JavaScriptCore/ChangeLog:25 > + (JSC::JSGlobalObject::reset): > + (JSC::JSGlobalObject::visitChildren): I don't like empty function lists like this :(. > Source/JavaScriptCore/runtime/WeakMapConstructor.cpp:46 > +static EncodedJSValue JSC_HOST_CALL constructWeakMapConstructor(ExecState* exec) Let's call this "constructWeakMap". > Source/JavaScriptCore/runtime/WeakMapData.cpp:44 > + , m_gcCleaner(this) Let's call this "m_deadKeyCleaner". > Source/JavaScriptCore/runtime/WeakMapData.cpp:66 > + // This sin't exact, but it is close enough, and proportional to the actual Should be "isn't". > Source/JavaScriptCore/runtime/WeakMapData.cpp:79 > + auto iter = m_map.find(key); > + if (iter != m_map.end()) { > + iter->value.set(callFrame->vm(), this, value); > + return; > + } > + // Here we force the write barrier on the key. > + m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value)); I think it would be better to use the "add 0" idiom here: auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value)); if (!result.isNewEntry) result.iterator->value = value; This avoids a second hash table lookup in the case where we add a new entry to the table. > Source/JavaScriptCore/runtime/WeakMapData.cpp:113 > + for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) { I think we usually use "it" for iterators. > Source/JavaScriptCore/runtime/WeakMapData.cpp:131 > + for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) { Ditto. > Source/JavaScriptCore/runtime/WeakMapData.cpp:140 > + for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) { Ditto.
> I think it would be better to use the "add 0" idiom here: > > auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value)); > if (!result.isNewEntry) > result.iterator->value = value; I meant: auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>());
Committed r155473: <http://trac.webkit.org/changeset/155473>