Ignore:
Timestamp:
Jan 2, 2018, 3:38:36 PM (8 years ago)
Author:
Caio Lima
Message:

[ESNext][BigInt] Implement BigIntConstructor and BigIntPrototype
https://bugs.webkit.org/show_bug.cgi?id=175359

Reviewed by Yusuke Suzuki.

JSTests:

  • bigIntTests.yaml:
  • stress/big-int-as-key.js: Added.
  • stress/big-int-constructor-gc.js: Added.
  • stress/big-int-constructor-oom.js: Added.
  • stress/big-int-constructor-properties.js: Added.
  • stress/big-int-constructor-prototype-prop-descriptor.js: Added.
  • stress/big-int-constructor-prototype.js: Added.
  • stress/big-int-constructor.js: Added.
  • stress/big-int-function-apply.js:
  • stress/big-int-length.js: Added.
  • stress/big-int-prop-descriptor.js: Added.
  • stress/big-int-proto-constructor.js: Added.
  • stress/big-int-proto-name.js: Added.
  • stress/big-int-prototype-properties.js: Added.
  • stress/big-int-prototype-proto.js: Added.
  • stress/big-int-prototype-value-of.js: Added.
  • stress/big-int-prototype-symbol-to-string-tag.js: Added.
  • stress/big-int-prototype-to-string-apply.js: Added.
  • stress/big-int-to-object.js: Added.
  • stress/big-int-to-string.js: Added.

Source/JavaScriptCore:

This patch is implementing BigIntConstructor and BigIntPrototype
following spec[1, 2]. As addition, we are also implementing BigIntObject
warapper to handle ToObject(v) abstract operation when "v" is a BigInt
primitive. With these classes, now it's possible to syntetize
BigInt.prototype and then call "toString", "valueOf" and
"toLocaleString" when the primitive is a BigInt.
BigIntConstructor exposes an API to parse other primitives such as
Number, Boolean and String to BigInt.
We decided to skip parseInt implementation, since it was removed from
spec.

[1] - https://tc39.github.io/proposal-bigint/#sec-bigint-constructor
[2] - https://tc39.github.io/proposal-bigint/#sec-properties-of-the-bigint-prototype-object

  • CMakeLists.txt:
  • DerivedSources.make:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • jsc.cpp:
  • runtime/BigIntConstructor.cpp: Added.

(JSC::BigIntConstructor::BigIntConstructor):
(JSC::BigIntConstructor::finishCreation):
(JSC::isSafeInteger):
(JSC::toBigInt):
(JSC::callBigIntConstructor):
(JSC::bigIntConstructorFuncAsUintN):
(JSC::bigIntConstructorFuncAsIntN):

  • runtime/BigIntConstructor.h: Added.

(JSC::BigIntConstructor::create):
(JSC::BigIntConstructor::createStructure):

  • runtime/BigIntObject.cpp: Added.

(JSC::BigIntObject::BigIntObject):
(JSC::BigIntObject::finishCreation):
(JSC::BigIntObject::toStringName):
(JSC::BigIntObject::defaultValue):

  • runtime/BigIntObject.h: Added.

(JSC::BigIntObject::create):
(JSC::BigIntObject::internalValue const):
(JSC::BigIntObject::createStructure):

  • runtime/BigIntPrototype.cpp: Added.

(JSC::BigIntPrototype::BigIntPrototype):
(JSC::BigIntPrototype::finishCreation):
(JSC::toThisBigIntValue):
(JSC::bigIntProtoFuncToString):
(JSC::bigIntProtoFuncToLocaleString):
(JSC::bigIntProtoFuncValueOf):

  • runtime/BigIntPrototype.h: Added.

(JSC::BigIntPrototype::create):
(JSC::BigIntPrototype::createStructure):

  • runtime/IntlCollator.cpp:

(JSC::IntlCollator::initializeCollator):

  • runtime/IntlNumberFormat.cpp:

(JSC::IntlNumberFormat::initializeNumberFormat):

  • runtime/JSBigInt.cpp:

(JSC::JSBigInt::createFrom):
(JSC::JSBigInt::parseInt):
(JSC::JSBigInt::toObject const):

  • runtime/JSBigInt.h:
  • runtime/JSCJSValue.cpp:

(JSC::JSValue::synthesizePrototype const):

  • runtime/JSCPoisonedPtr.cpp:
  • runtime/JSCell.cpp:

(JSC::JSCell::toObjectSlow const):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::bigIntPrototype const):
(JSC::JSGlobalObject::bigIntObjectStructure const):

  • runtime/StructureCache.h:
  • runtime/StructureInlines.h:

(JSC::prototypeForLookupPrimitiveImpl):

File:
1 edited

Legend:

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

    r225891 r226338  
    2424#include "ArrayAllocationProfile.h"
    2525#include "ArrayBufferSharingMode.h"
     26#include "BigIntPrototype.h"
    2627#include "BooleanPrototype.h"
    2728#include "ExceptionHelpers.h"
     
    129130    macro(JSPromise, promise, promise, JSPromise, Promise, object)
    130131
     132#define FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
     133    macro(BigInt, bigInt, bigIntObject, BigIntObject, BigInt, object)
     134
    131135#define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
    132136    macro(StringIterator, stringIterator, stringIterator, JSStringIterator, StringIterator, iterator) \
     
    161165class IteratorPrototype;
    162166FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
     167FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DECLARE_SIMPLE_BUILTIN_TYPE)
    163168FOR_EACH_LAZY_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
    164169FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
     
    356361
    357362    FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
     363    FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
    358364    FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
    359365   
     
    571577    SymbolPrototype* symbolPrototype() const { return m_symbolPrototype.get(); }
    572578    NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
     579    BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
    573580    JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
    574581    RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
     
    647654    Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
    648655    Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
     656    Structure* bigIntObjectStructure() const { return m_bigIntObjectStructure.get(); }
    649657    Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(); }
    650658    Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
     
    709717
    710718    FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
     719    FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
    711720    FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
    712721    FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
Note: See TracChangeset for help on using the changeset viewer.