Ignore:
Timestamp:
Aug 29, 2013, 5:55:34 PM (12 years ago)
Author:
[email protected]
Message:

Implement ES6 Map object
https://bugs.webkit.org/show_bug.cgi?id=120333

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Implement support for the ES6 Map type and related classes.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • heap/CopyToken.h: Add a new token to track copying the backing store
  • runtime/CommonIdentifiers.h: Add new identifiers
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:

Add new structures and prototypes

  • runtime/JSMap.cpp: Added.
  • runtime/JSMap.h: Added.

New JSMap class to represent a Map instance

  • runtime/MapConstructor.cpp: Added.
  • runtime/MapConstructor.h: Added.

The Map constructor

  • runtime/MapData.cpp: Added.
  • runtime/MapData.h: Added.

The most interesting data structure. The roughly corresponds
to the ES6 notion of MapData. It provides the core JSValue->JSValue
map implementation. We implement it using 2 hashtables and a flat
table. Due to the different semantics of string comparisons vs.
all others we need have one map keyed by String and the other by
generic JSValue. The actual table is represented more or less
exactly as described in the ES6 draft - a single contiguous list of
key/value pairs. The entire map could be achieved with just this
table, however we need the HashMaps in order to maintain O(1) lookup.

Deleted values are simply cleared as the draft says, however the
implementation compacts the storage on copy as long as the are no
active iterators.

  • runtime/MapPrototype.cpp: Added.
  • runtime/MapPrototype.h: Added.

Implement Map prototype functions

  • runtime/VM.cpp:

Add new structures.

LayoutTests:

Tests

  • fast/js/basic-map-expected.txt: Added.
  • fast/js/basic-map.html: Added.
  • fast/js/script-tests/basic-map.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r154847 r154861  
    6464class JSStack;
    6565class LLIntOffsetsExtractor;
     66class MapPrototype;
    6667class NativeErrorConstructor;
    6768class ProgramCodeBlock;
     
    151152    WriteBarrier<JSPromisePrototype> m_promisePrototype;
    152153    WriteBarrier<JSPromiseResolverPrototype> m_promiseResolverPrototype;
     154    WriteBarrier<MapPrototype> m_mapPrototype;
    153155
    154156    WriteBarrier<Structure> m_withScopeStructure;
     
    192194#endif // ENABLE(PROMISES)
    193195
     196    WriteBarrier<Structure> m_mapDataStructure;
     197    WriteBarrier<Structure> m_mapStructure;
     198   
    194199    WriteBarrier<JSArrayBufferPrototype> m_arrayBufferPrototype;
    195200    WriteBarrier<Structure> m_arrayBufferStructure;
     
    382387    Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
    383388    Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
     389    Structure* mapStructure() const { return m_mapStructure.get(); }
     390    Structure* mapDataStructure() const { return m_mapDataStructure.get(); }
    384391    Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
    385392    Structure* regExpStructure() const { return m_regExpStructure.get(); }
Note: See TracChangeset for help on using the changeset viewer.