Ignore:
Timestamp:
Apr 4, 2015, 7:32:53 AM (10 years ago)
Author:
Yusuke Suzuki
Message:

Implement ES6 Object.getOwnPropertySymbols
https://bugs.webkit.org/show_bug.cgi?id=141106

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This patch implements Object.getOwnPropertySymbols.
One technical issue is that, since we use private symbols (such as @Object) in the
privileged JS code in builtins/, they should not be exposed.
To distinguish them from the usual symbols, check the target StringImpl* is a not private name
before adding it into PropertyNameArray.

To check the target StringImpl* is a private name, we leverage privateToPublic map in BuiltinNames
since all private symbols are held in this map.

  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::createExecutableInternal):

  • builtins/BuiltinNames.h:

(JSC::BuiltinNames::isPrivateName):

  • runtime/CommonIdentifiers.cpp:

(JSC::CommonIdentifiers::isPrivateName):

  • runtime/CommonIdentifiers.h:
  • runtime/EnumerationMode.h:

(JSC::EnumerationMode::EnumerationMode):
(JSC::EnumerationMode::includeSymbolProperties):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSLexicalEnvironment.cpp:

(JSC::JSLexicalEnvironment::getOwnNonIndexPropertyNames):

  • runtime/JSSymbolTableObject.cpp:

(JSC::JSSymbolTableObject::getOwnNonIndexPropertyNames):

  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructor::finishCreation):
(JSC::objectConstructorGetOwnPropertySymbols):
(JSC::defineProperties):
(JSC::objectConstructorSeal):
(JSC::objectConstructorFreeze):
(JSC::objectConstructorIsSealed):
(JSC::objectConstructorIsFrozen):

  • runtime/ObjectConstructor.h:

(JSC::ObjectConstructor::create):

  • runtime/Structure.cpp:

(JSC::Structure::getPropertyNamesFromStructure):

  • tests/stress/object-get-own-property-symbols-perform-to-object.js: Added.

(compare):

  • tests/stress/object-get-own-property-symbols.js: Added.

(forIn):

  • tests/stress/symbol-define-property.js: Added.

(testSymbol):

  • tests/stress/symbol-seal-and-freeze.js: Added.
  • tests/stress/symbol-with-json.js: Added.

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/script-tests/Object-getOwnPropertyNames.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Structure.cpp

    r182280 r182343  
    940940    for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
    941941        ASSERT(hasNonEnumerableProperties() || !(iter->attributes & DontEnum));
    942         if (!iter->key->isSymbol() && (!(iter->attributes & DontEnum) || mode.includeDontEnumProperties())) {
     942        if (!(iter->attributes & DontEnum) || mode.includeDontEnumProperties()) {
     943            if (iter->key->isSymbol() && !mode.includeSymbolProperties())
     944                continue;
    943945            if (knownUnique)
    944946                propertyNames.addKnownUnique(iter->key);
Note: See TracChangeset for help on using the changeset viewer.