Commit bfcc048e authored by oliver@apple.com's avatar oliver@apple.com

Support WeakMap

https://bugs.webkit.org/show_bug.cgi?id=120912

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Add support for ES6 WeakMap.  Add the cluster of boilerplate
classes around the core WeakMapData class.

WeakMapData is a simple object->value hash table that uses a
combo of WeakReferenceHarvester to conditionally keep the weak
value reference live, and UnconditionalFinalizer to clean the
dead keys from the table post-GC.

* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Target.pri:
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::weakMapDataStructure):
* runtime/JSWeakMap.cpp: Added.
(JSC::JSWeakMap::finishCreation):
(JSC::JSWeakMap::visitChildren):
* runtime/JSWeakMap.h: Added.
(JSC::JSWeakMap::createStructure):
(JSC::JSWeakMap::create):
(JSC::JSWeakMap::weakMapData):
(JSC::JSWeakMap::JSWeakMap):
* runtime/WeakMapConstructor.cpp: Added.
(JSC::WeakMapConstructor::finishCreation):
(JSC::constructWeakMap):
(JSC::WeakMapConstructor::getConstructData):
(JSC::WeakMapConstructor::getCallData):
* runtime/WeakMapConstructor.h: Added.
(JSC::WeakMapConstructor::create):
(JSC::WeakMapConstructor::createStructure):
(JSC::WeakMapConstructor::WeakMapConstructor):
* runtime/WeakMapData.cpp: Added.
(JSC::WeakMapData::WeakMapData):
(JSC::WeakMapData::finishCreation):
(JSC::WeakMapData::destroy):
(JSC::WeakMapData::visitChildren):
(JSC::WeakMapData::set):
(JSC::WeakMapData::get):
(JSC::WeakMapData::remove):
(JSC::WeakMapData::contains):
(JSC::WeakMapData::clear):
(JSC::WeakMapData::DeadKeyCleaner::visitWeakReferences):
(JSC::WeakMapData::DeadKeyCleaner::finalizeUnconditionally):
* runtime/WeakMapData.h: Added.
(JSC::WeakMapData::create):
(JSC::WeakMapData::createStructure):
(JSC::WeakMapData::DeadKeyCleaner::DeadKeyCleaner):
* runtime/WeakMapPrototype.cpp: Added.
(JSC::WeakMapPrototype::finishCreation):
(JSC::getWeakMapData):
(JSC::protoFuncWeakMapClear):
(JSC::protoFuncWeakMapDelete):
(JSC::protoFuncWeakMapGet):
(JSC::protoFuncWeakMapHas):
(JSC::protoFuncWeakMapSet):
* runtime/WeakMapPrototype.h: Added.
(JSC::WeakMapPrototype::create):
(JSC::WeakMapPrototype::createStructure):
(JSC::WeakMapPrototype::WeakMapPrototype):

LayoutTests:

Basic tests.

* js/basic-weakmap-expected.txt: Added.
* js/basic-weakmap.html: Added.
* js/script-tests/basic-weakmap.js: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155473 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3df3d082
2013-09-10 Oliver Hunt <oliver@apple.com>
Support WeakMap
https://bugs.webkit.org/show_bug.cgi?id=120912
Reviewed by Geoffrey Garen.
Basic tests.
* js/basic-weakmap-expected.txt: Added.
* js/basic-weakmap.html: Added.
* js/script-tests/basic-weakmap.js: Added.
2013-09-10 Ryosuke Niwa <rniwa@webkit.org>
Fix race in fast/loader/onunload-form-submit-crash.html
Tests basic correctness of ES WeakMap object
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS WeakMap instanceof WeakMap is false
PASS WeakMap.prototype instanceof WeakMap is false
PASS new WeakMap() instanceof WeakMap is true
PASS WeakMap() threw exception TypeError: Function is not a function (evaluating 'WeakMap()').
PASS map.set(0, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set(0.5, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set('foo', 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set(true, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set(false, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set(null, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.set(undefined, 1) threw exception TypeError: Attempted to set a non-object key in a WeakMap.
PASS map.get(0) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get(0.5) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get('foo') threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get(true) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get(false) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get(null) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.get(undefined) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(0) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(0.5) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has('foo') threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(true) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(false) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(null) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.has(undefined) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(0) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(0.5) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete('foo') threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(true) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(false) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(null) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.delete(undefined) threw exception TypeError: A WeakMap cannot have a non-object key.
PASS map.set(new String('foo'), 'foo') is map
PASS map.get(new String('foo')) is undefined
PASS map.has(new String('foo')) is false
PASS Math.abs(currentObjectCount - keyLessObjectCount) < 100 is true
PASS (keyLessObjectCount - valueLessObjectCount) > 1500 is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script src="script-tests/basic-weakmap.js"></script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>
description("Tests basic correctness of ES WeakMap object");
// Currently we don't support iterators, so we throw
// on any non-throwing parameters
shouldBeFalse("WeakMap instanceof WeakMap");
shouldBeFalse("WeakMap.prototype instanceof WeakMap");
shouldBeTrue("new WeakMap() instanceof WeakMap");
shouldThrow("WeakMap()");
var map = new WeakMap;
shouldThrow("map.set(0, 1)")
shouldThrow("map.set(0.5, 1)")
shouldThrow("map.set('foo', 1)")
shouldThrow("map.set(true, 1)")
shouldThrow("map.set(false, 1)")
shouldThrow("map.set(null, 1)")
shouldThrow("map.set(undefined, 1)")
shouldThrow("map.get(0)")
shouldThrow("map.get(0.5)")
shouldThrow("map.get('foo')")
shouldThrow("map.get(true)")
shouldThrow("map.get(false)")
shouldThrow("map.get(null)")
shouldThrow("map.get(undefined)")
shouldThrow("map.has(0)")
shouldThrow("map.has(0.5)")
shouldThrow("map.has('foo')")
shouldThrow("map.has(true)")
shouldThrow("map.has(false)")
shouldThrow("map.has(null)")
shouldThrow("map.has(undefined)")
shouldThrow("map.delete(0)")
shouldThrow("map.delete(0.5)")
shouldThrow("map.delete('foo')")
shouldThrow("map.delete(true)")
shouldThrow("map.delete(false)")
shouldThrow("map.delete(null)")
shouldThrow("map.delete(undefined)")
shouldBe("map.set(new String('foo'), 'foo')", "map");
shouldBe("map.get(new String('foo'))", "undefined");
shouldBeFalse("map.has(new String('foo'))");
var keys = [];
var values = [];
var count = 2000;
for (var i = 0; i < count; i++) {
keys[i] = {}
values[i] = {v : keys[i]}
keys[i].v = values[i]
}
for (var i = 0; i < count; i++) {
map.set(keys[i], values[i])
}
gc();
if (this.GCController) {
var currentObjectCount = GCController.getJSObjectCount()
keys = null;
gc();
var keyLessObjectCount = GCController.getJSObjectCount()
// Somewhat approximate
shouldBeTrue("Math.abs(currentObjectCount - keyLessObjectCount) < 100");
for (var i = 0; i < count; i++) {
if (map.get(values[i].v) != values[i])
fail("Key was incorrectly removed from weak map");
}
values = null;
gc();
var valueLessObjectCount = GCController.getJSObjectCount()
shouldBeTrue("(keyLessObjectCount - valueLessObjectCount) > " + (count * 3 / 4));
}
......@@ -342,6 +342,7 @@ set(JavaScriptCore_SOURCES
runtime/JSTypedArrayPrototypes.cpp
runtime/JSTypedArrays.cpp
runtime/JSVariableObject.cpp
runtime/JSWeakMap.cpp
runtime/JSWithScope.cpp
runtime/JSWrapperObject.cpp
runtime/LiteralParser.cpp
......@@ -396,6 +397,9 @@ set(JavaScriptCore_SOURCES
runtime/VM.cpp
runtime/Watchdog.cpp
runtime/WatchdogNone.cpp
runtime/WeakMapConstructor.cpp
runtime/WeakMapData.cpp
runtime/WeakMapPrototype.cpp
tools/CodeProfile.cpp
tools/CodeProfiling.cpp
......
2013-09-09 Oliver Hunt <oliver@apple.com>
Support WeakMap
https://bugs.webkit.org/show_bug.cgi?id=120912
Reviewed by Geoffrey Garen.
Add support for ES6 WeakMap. Add the cluster of boilerplate
classes around the core WeakMapData class.
WeakMapData is a simple object->value hash table that uses a
combo of WeakReferenceHarvester to conditionally keep the weak
value reference live, and UnconditionalFinalizer to clean the
dead keys from the table post-GC.
* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Target.pri:
* runtime/CommonIdentifiers.h:
* runtime/JSGlobalObject.cpp:
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::weakMapDataStructure):
* runtime/JSWeakMap.cpp: Added.
(JSC::JSWeakMap::finishCreation):
(JSC::JSWeakMap::visitChildren):
* runtime/JSWeakMap.h: Added.
(JSC::JSWeakMap::createStructure):
(JSC::JSWeakMap::create):
(JSC::JSWeakMap::weakMapData):
(JSC::JSWeakMap::JSWeakMap):
* runtime/WeakMapConstructor.cpp: Added.
(JSC::WeakMapConstructor::finishCreation):
(JSC::constructWeakMap):
(JSC::WeakMapConstructor::getConstructData):
(JSC::WeakMapConstructor::getCallData):
* runtime/WeakMapConstructor.h: Added.
(JSC::WeakMapConstructor::create):
(JSC::WeakMapConstructor::createStructure):
(JSC::WeakMapConstructor::WeakMapConstructor):
* runtime/WeakMapData.cpp: Added.
(JSC::WeakMapData::WeakMapData):
(JSC::WeakMapData::finishCreation):
(JSC::WeakMapData::destroy):
(JSC::WeakMapData::visitChildren):
(JSC::WeakMapData::set):
(JSC::WeakMapData::get):
(JSC::WeakMapData::remove):
(JSC::WeakMapData::contains):
(JSC::WeakMapData::clear):
(JSC::WeakMapData::DeadKeyCleaner::visitWeakReferences):
(JSC::WeakMapData::DeadKeyCleaner::finalizeUnconditionally):
* runtime/WeakMapData.h: Added.
(JSC::WeakMapData::create):
(JSC::WeakMapData::createStructure):
(JSC::WeakMapData::DeadKeyCleaner::DeadKeyCleaner):
* runtime/WeakMapPrototype.cpp: Added.
(JSC::WeakMapPrototype::finishCreation):
(JSC::getWeakMapData):
(JSC::protoFuncWeakMapClear):
(JSC::protoFuncWeakMapDelete):
(JSC::protoFuncWeakMapGet):
(JSC::protoFuncWeakMapHas):
(JSC::protoFuncWeakMapSet):
* runtime/WeakMapPrototype.h: Added.
(JSC::WeakMapPrototype::create):
(JSC::WeakMapPrototype::createStructure):
(JSC::WeakMapPrototype::WeakMapPrototype):
2013-09-10 Joseph Pecoraro <pecoraro@apple.com>
Web Inspector: [JSC] Caught exception is treated as uncaught
......
......@@ -921,6 +921,8 @@ javascriptcore_sources += \
Source/JavaScriptCore/runtime/JSUint32Array.h \
Source/JavaScriptCore/runtime/JSUint8Array.h \
Source/JavaScriptCore/runtime/JSUint8ClampedArray.h \
Source/JavaScriptCore/runtime/JSWeakMap.cpp \
Source/JavaScriptCore/runtime/JSWeakMap.h \
Source/JavaScriptCore/runtime/JSWithScope.cpp \
Source/JavaScriptCore/runtime/JSNameScope.cpp \
Source/JavaScriptCore/runtime/JSNameScope.h \
......@@ -1070,6 +1072,12 @@ javascriptcore_sources += \
Source/JavaScriptCore/runtime/Watchdog.h \
Source/JavaScriptCore/runtime/WatchdogNone.cpp \
Source/JavaScriptCore/runtime/WeakGCMap.h \
Source/JavaScriptCore/runtime/WeakMapConstructor.cpp \
Source/JavaScriptCore/runtime/WeakMapConstructor.h \
Source/JavaScriptCore/runtime/WeakMapData.cpp \
Source/JavaScriptCore/runtime/WeakMapData.h \
Source/JavaScriptCore/runtime/WeakMapPrototype.cpp \
Source/JavaScriptCore/runtime/WeakMapPrototype.h \
Source/JavaScriptCore/runtime/WeakRandom.h \
Source/JavaScriptCore/runtime/WriteBarrier.h \
Source/JavaScriptCore/tools/CodeProfile.cpp \
......
......@@ -493,6 +493,7 @@
<ClCompile Include="..\runtime\JSTypedArrayPrototypes.cpp" />
<ClCompile Include="..\runtime\JSTypedArrays.cpp" />
<ClCompile Include="..\runtime\JSVariableObject.cpp" />
<ClCompile Include="..\runtime\JSWeakMap.cpp" />
<ClCompile Include="..\runtime\JSWithScope.cpp" />
<ClCompile Include="..\runtime\JSWrapperObject.cpp" />
<ClCompile Include="..\runtime\LiteralParser.cpp" />
......@@ -546,6 +547,9 @@
<ClCompile Include="..\runtime\VM.cpp" />
<ClCompile Include="..\runtime\Watchdog.cpp" />
<ClCompile Include="..\runtime\WatchdogNone.cpp" />
<ClCompile Include="..\runtime\WeakMapConstructor.cpp" />
<ClCompile Include="..\runtime\WeakMapData.cpp" />
<ClCompile Include="..\runtime\WeakMapPrototype.cpp" />
<ClCompile Include="..\tools\CodeProfile.cpp" />
<ClCompile Include="..\tools\CodeProfiling.cpp" />
<ClCompile Include="..\yarr\YarrCanonicalizeUCS2.cpp" />
......@@ -934,6 +938,7 @@
<ClInclude Include="..\runtime\JSUint8Array.h" />
<ClInclude Include="..\runtime\JSUint8ClampedArray.h" />
<ClInclude Include="..\runtime\JSVariableObject.h" />
<ClInclude Include="..\runtime\JSWeakMap.h" />
<ClInclude Include="..\runtime\JSWithScope.h" />
<ClInclude Include="..\runtime\JSWrapperObject.h" />
<ClInclude Include="..\runtime\LiteralParser.h" />
......@@ -1009,6 +1014,9 @@
<ClInclude Include="..\runtime\VM.h" />
<ClInclude Include="..\runtime\Watchdog.h" />
<ClInclude Include="..\runtime\WeakGCMap.h" />
<ClInclude Include="..\runtime\WeakMapConstructor.h" />
<ClInclude Include="..\runtime\WeakMapData.h" />
<ClInclude Include="..\runtime\WeakMapPrototype.h" />
<ClInclude Include="..\runtime\WeakRandom.h" />
<ClInclude Include="..\runtime\WriteBarrier.h" />
<ClInclude Include="..\tools\CodeProfile.h" />
......
......@@ -612,6 +612,9 @@
<ClCompile Include="..\runtime\JSWithScope.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\runtime\JSWeakMap.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\runtime\JSWrapperObject.cpp">
<Filter>runtime</Filter>
</ClCompile>
......@@ -858,6 +861,15 @@
<ClCompile Include="..\runtime\JSPromise.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\runtime\WeakMapConstructor.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\runtime\WeakMapData.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\runtime\WeakMapPrototype.cpp">
<Filter>runtime</Filter>
</ClCompile>
<ClCompile Include="..\heap\CodeBlockSet.cpp">
<Filter>heap</Filter>
</ClCompile>
......
......@@ -939,6 +939,14 @@
A7C1EAF017987AB600299DB2 /* JSStackInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = A7C1EAEB17987AB600299DB2 /* JSStackInlines.h */; };
A7C1EAF117987AB600299DB2 /* StackVisitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7C1EAEC17987AB600299DB2 /* StackVisitor.cpp */; };
A7C1EAF217987AB600299DB2 /* StackVisitor.h in Headers */ = {isa = PBXBuildFile; fileRef = A7C1EAED17987AB600299DB2 /* StackVisitor.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3ADD17DA41AE006538AF /* WeakMapConstructor.cpp */; };
A7CA3AE417DA41AE006538AF /* WeakMapConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3ADE17DA41AE006538AF /* WeakMapConstructor.h */; };
A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3ADF17DA41AE006538AF /* WeakMapPrototype.cpp */; };
A7CA3AE617DA41AE006538AF /* WeakMapPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */; };
A7CA3AE717DA41AE006538AF /* JSWeakMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */; };
A7CA3AE817DA41AE006538AF /* JSWeakMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AE217DA41AE006538AF /* JSWeakMap.h */; };
A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA3AE917DA5168006538AF /* WeakMapData.cpp */; };
A7CA3AEC17DA5168006538AF /* WeakMapData.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA3AEA17DA5168006538AF /* WeakMapData.h */; };
A7D89CF217A0B8CC00773AD8 /* DFGBasicBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D89CE317A0B8CC00773AD8 /* DFGBasicBlock.cpp */; };
A7D89CF317A0B8CC00773AD8 /* DFGBlockInsertionSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D89CE417A0B8CC00773AD8 /* DFGBlockInsertionSet.cpp */; };
A7D89CF417A0B8CC00773AD8 /* DFGBlockInsertionSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D89CE517A0B8CC00773AD8 /* DFGBlockInsertionSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -2147,6 +2155,14 @@
A7C1EAED17987AB600299DB2 /* StackVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackVisitor.h; sourceTree = "<group>"; };
A7C225CC139981F100FF1662 /* KeywordLookupGenerator.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = KeywordLookupGenerator.py; sourceTree = "<group>"; };
A7C225CD1399849C00FF1662 /* KeywordLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeywordLookup.h; sourceTree = "<group>"; };
A7CA3ADD17DA41AE006538AF /* WeakMapConstructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapConstructor.cpp; sourceTree = "<group>"; };
A7CA3ADE17DA41AE006538AF /* WeakMapConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapConstructor.h; sourceTree = "<group>"; };
A7CA3ADF17DA41AE006538AF /* WeakMapPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapPrototype.cpp; sourceTree = "<group>"; };
A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapPrototype.h; sourceTree = "<group>"; };
A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWeakMap.cpp; sourceTree = "<group>"; };
A7CA3AE217DA41AE006538AF /* JSWeakMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWeakMap.h; sourceTree = "<group>"; };
A7CA3AE917DA5168006538AF /* WeakMapData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapData.cpp; sourceTree = "<group>"; };
A7CA3AEA17DA5168006538AF /* WeakMapData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapData.h; sourceTree = "<group>"; };
A7D89CE317A0B8CC00773AD8 /* DFGBasicBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGBasicBlock.cpp; path = dfg/DFGBasicBlock.cpp; sourceTree = "<group>"; };
A7D89CE417A0B8CC00773AD8 /* DFGBlockInsertionSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGBlockInsertionSet.cpp; path = dfg/DFGBlockInsertionSet.cpp; sourceTree = "<group>"; };
A7D89CE517A0B8CC00773AD8 /* DFGBlockInsertionSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGBlockInsertionSet.h; path = dfg/DFGBlockInsertionSet.h; sourceTree = "<group>"; };
......@@ -3380,6 +3396,14 @@
14BFCE6810CDB1FC00364CCE /* WeakGCMap.h */,
1420BE7A10AA6DDB00F455D2 /* WeakRandom.h */,
A7DCB77912E3D90500911940 /* WriteBarrier.h */,
A7CA3ADD17DA41AE006538AF /* WeakMapConstructor.cpp */,
A7CA3ADE17DA41AE006538AF /* WeakMapConstructor.h */,
A7CA3ADF17DA41AE006538AF /* WeakMapPrototype.cpp */,
A7CA3AE017DA41AE006538AF /* WeakMapPrototype.h */,
A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */,
A7CA3AE217DA41AE006538AF /* JSWeakMap.h */,
A7CA3AE917DA5168006538AF /* WeakMapData.cpp */,
A7CA3AEA17DA5168006538AF /* WeakMapData.h */,
);
path = runtime;
sourceTree = "<group>";
......@@ -3992,6 +4016,7 @@
0FC0976A1468A6F700CF2442 /* DFGOSRExit.h in Headers */,
0F235BEC17178E7300690C7F /* DFGOSRExitBase.h in Headers */,
0FFB921C16D02F110055A5DB /* DFGOSRExitCompilationInfo.h in Headers */,
A7CA3AEC17DA5168006538AF /* WeakMapData.h in Headers */,
0FC0977114693AF500CF2442 /* DFGOSRExitCompiler.h in Headers */,
0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */,
0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */,
......@@ -4212,6 +4237,7 @@
14874AE615EBDE4A002E3587 /* JSScope.h in Headers */,
A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */,
0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
A7CA3AE817DA41AE006538AF /* JSWeakMap.h in Headers */,
A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */,
BC18C45E0E16F5CD00B34460 /* JSStack.h in Headers */,
A7C1EAF017987AB600299DB2 /* JSStackInlines.h in Headers */,
......@@ -4337,6 +4363,7 @@
0FF729BA166AD360000F5BA3 /* ProfilerCompilation.h in Headers */,
0FF729BB166AD360000F5BA3 /* ProfilerCompilationKind.h in Headers */,
0FD8A32617D51F5700CA2C40 /* DFGOSREntrypointCreationPhase.h in Headers */,
A7CA3AE417DA41AE006538AF /* WeakMapConstructor.h in Headers */,
0FF729BC166AD360000F5BA3 /* ProfilerCompiledBytecode.h in Headers */,
0FF729BD166AD360000F5BA3 /* ProfilerDatabase.h in Headers */,
0FF729BE166AD360000F5BA3 /* ProfilerExecutionCounter.h in Headers */,
......@@ -4402,6 +4429,7 @@
BC18C46A0E16F5CD00B34460 /* StringPrototype.h in Headers */,
142E313B134FF0A600AFADB5 /* Strong.h in Headers */,
145722861437E140005FDE26 /* StrongInlines.h in Headers */,
A7CA3AE617DA41AE006538AF /* WeakMapPrototype.h in Headers */,
BCDE3AB80E6C82F5001453A7 /* Structure.h in Headers */,
7E4EE7090EBB7963005934AA /* StructureChain.h in Headers */,
0FD2C92416D01EE900C7803F /* StructureInlines.h in Headers */,
......@@ -4986,6 +5014,7 @@
147F39CC107EC37600427A48 /* FunctionPrototype.cpp in Sources */,
C2D58C3415912FEE0021A844 /* GCActivityCallback.cpp in Sources */,
0F766D2F15A8DCE0008F363E /* GCAwareJITStubRoutine.cpp in Sources */,
A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
C2239D1A16262BDD005AC5FD /* GCThread.cpp in Sources */,
C21122E115DD9AB300790E3A /* GCThreadSharedData.cpp in Sources */,
0F93329F14CA7DCA0085F3C6 /* GetByIdStatus.cpp in Sources */,
......@@ -5127,6 +5156,7 @@
14469DE2107EC7E700650446 /* NumberConstructor.cpp in Sources */,
14469DE3107EC7E700650446 /* NumberObject.cpp in Sources */,
14469DE4107EC7E700650446 /* NumberPrototype.cpp in Sources */,
A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */,
86F3EEBE168CDE930077B92A /* ObjCCallbackFunction.mm in Sources */,
14469DE5107EC7E700650446 /* ObjectConstructor.cpp in Sources */,
14469DE6107EC7E700650446 /* ObjectPrototype.cpp in Sources */,
......@@ -5160,9 +5190,11 @@
ADE39FFF16DD144B0003CD4A /* PropertyTable.cpp in Sources */,
1474C33C16AA2D9B0062F01D /* PrototypeMap.cpp in Sources */,
0F9332A314CA7DD70085F3C6 /* PutByIdStatus.cpp in Sources */,
A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
0FF60AC316740F8800029779 /* ReduceWhitespace.cpp in Sources */,
14280841107EC0930013E7B2 /* RegExp.cpp in Sources */,
A1712B3B11C7B212007A5315 /* RegExpCache.cpp in Sources */,
A7CA3AE717DA41AE006538AF /* JSWeakMap.cpp in Sources */,
8642C510151C06A90046D4EF /* RegExpCachedResult.cpp in Sources */,
0FD8A32B17D51F5700CA2C40 /* DFGToFTLForOSREntryDeferredCompilationCallback.cpp in Sources */,
14280842107EC0930013E7B2 /* RegExpConstructor.cpp in Sources */,
......
......@@ -350,6 +350,7 @@ SOURCES += \
runtime/JSTypedArrayPrototypes.cpp \
runtime/JSTypedArrays.cpp \
runtime/JSVariableObject.cpp \
runtime/JSWeakMap.cpp \
runtime/JSWithScope.cpp \
runtime/JSWrapperObject.cpp \
runtime/LiteralParser.cpp \
......@@ -404,6 +405,9 @@ SOURCES += \
runtime/VM.cpp \
runtime/Watchdog.cpp \
runtime/WatchdogNone.cpp \
runtime/WeakMapConstructor.cpp \
runtime/WeakMapData.cpp \
runtime/WeakMapPrototype.cpp \
tools/CodeProfile.cpp \
tools/CodeProfiling.cpp \
yarr/YarrJIT.cpp \
......
......@@ -143,6 +143,7 @@
macro(size) \
macro(Map)\
macro(Set)\
macro(WeakMap)\
macro(add)
#define JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(macro) \
......
......@@ -71,6 +71,7 @@
#include "JSTypedArrayConstructors.h"
#include "JSTypedArrayPrototypes.h"
#include "JSTypedArrays.h"
#include "JSWeakMap.h"
#include "JSWithScope.h"
#include "LegacyProfiler.h"
#include "Lookup.h"
......@@ -99,6 +100,9 @@
#include "StrictEvalActivation.h"
#include "StringConstructor.h"
#include "StringPrototype.h"
#include "WeakMapConstructor.h"
#include "WeakMapData.h"
#include "WeakMapPrototype.h"
#if ENABLE(PROMISES)
#include "JSPromise.h"
......@@ -309,6 +313,7 @@ void JSGlobalObject::reset(JSValue prototype)
m_mapDataStructure.set(exec->vm(), this, MapData::createStructure(exec->vm(), this, jsNull()));
m_weakMapDataStructure.set(exec->vm(), this, WeakMapData::createStructure(exec->vm(), this, jsNull()));
#define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
m_ ## lowerName ## Prototype.set(exec->vm(), this, capitalName##Prototype::create(exec, this, capitalName##Prototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); \
......@@ -640,6 +645,7 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
#undef VISIT_SIMPLE_TYPE
visitor.append(&thisObject->m_mapDataStructure);
visitor.append(&thisObject->m_weakMapDataStructure);
for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
visitor.append(&thisObject->m_typedArrays[i].prototype);
......
......@@ -80,6 +80,7 @@ struct HashTable;
macro(Number, number, numberObject, NumberObject, Number) \
macro(Error, error, error, ErrorInstance, Error) \
macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
macro(WeakMap, weakMap, weakMap, JSWeakMap, WeakMap) \
#define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
class JS ## capitalName; \
......@@ -200,6 +201,7 @@ protected:
#endif // ENABLE(PROMISES)
WriteBarrier<Structure> m_mapDataStructure;
WriteBarrier<Structure> m_weakMapDataStructure;
#define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
......@@ -398,6 +400,7 @@ public:
Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
Structure* mapStructure() const { return m_mapStructure.get(); }
Structure* mapDataStructure() const { return m_mapDataStructure.get(); }
Structure* weakMapDataStructure() const { return m_weakMapDataStructure.get(); }
Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
Structure* regExpStructure() const { return m_regExpStructure.get(); }
Structure* setStructure() const { return m_setStructure.get(); }
......
/*
* Copyright (C) 2013 Apple, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSWeakMap.h"
#include "JSCJSValueInlines.h"
#include "SlotVisitorInlines.h"
#include "WeakMapData.h"
namespace JSC {
const ClassInfo JSWeakMap::s_info = { "WeakMap", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSWeakMap) };
void JSWeakMap::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
m_weakMapData.set(vm, this, WeakMapData::create(vm, globalObject));
}
void JSWeakMap::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
Base::visitChildren(cell, visitor);
JSWeakMap* thisObj = jsCast<JSWeakMap*>(cell);
visitor.append(&thisObj->m_weakMapData);
}
}
/*
* Copyright (C) 2013 Apple, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JSWeakMap_h
#define JSWeakMap_h
#include "JSObject.h"
namespace JSC {
class WeakMapData;
class JSWeakMap : public JSNonFinalObject {
public:
typedef JSNonFinalObject Base;
DECLARE_EXPORT_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static JSWeakMap* create(ExecState* exec, Structure* structure)
{
VM& vm = exec->vm();
JSWeakMap* instance = new (NotNull, allocateCell<JSWeakMap>(vm.heap)) JSWeakMap(vm, structure);
instance->finishCreation(vm, structure->globalObject());
return instance;
}
WeakMapData* weakMapData() { return m_weakMapData.get(); }
JSValue get(CallFrame*, JSObject*);
bool has(CallFrame*, JSObject*);
bool remove(CallFrame*, JSObject*);
void set(CallFrame*, JSObject*, JSValue);
void clear(CallFrame*);
private:
static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
JSWeakMap(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(VM&, JSGlobalObject*);
static void visitChildren(JSCell*, SlotVisitor&);
WriteBarrier<WeakMapData> m_weakMapData;
};
}
#endif // !defined(JSWeakMap_h)
/*
* Copyright (C) 2013 Apple, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.