[ESNext][BigInt] Implement BigIntConstructor and BigIntPrototype
authorticaiolima@gmail.com <ticaiolima@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jan 2018 23:38:36 +0000 (23:38 +0000)
committerticaiolima@gmail.com <ticaiolima@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jan 2018 23:38:36 +0000 (23:38 +0000)
commit869c642da633eb952e06ecc5d715412a9ed6fd7c
tree5a5463463885dee1c492d28b5234663f49dc9578
parentf59d0e81529ce791985a00b2ebd94e2baa733bad
[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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226338 268f45cc-cd09-0410-ab3c-d52691b4dbfc
41 files changed:
JSTests/ChangeLog
JSTests/bigIntTests.yaml
JSTests/stress/big-int-as-key.js [new file with mode: 0644]
JSTests/stress/big-int-constructor-gc.js [new file with mode: 0644]
JSTests/stress/big-int-constructor-oom.js [new file with mode: 0644]
JSTests/stress/big-int-constructor-properties.js [new file with mode: 0644]
JSTests/stress/big-int-constructor-prototype-prop-descriptor.js [new file with mode: 0644]
JSTests/stress/big-int-constructor-prototype.js [new file with mode: 0644]
JSTests/stress/big-int-constructor.js [new file with mode: 0644]
JSTests/stress/big-int-length.js [new file with mode: 0644]
JSTests/stress/big-int-prop-descriptor.js [new file with mode: 0644]
JSTests/stress/big-int-proto-constructor.js [new file with mode: 0644]
JSTests/stress/big-int-proto-name.js [new file with mode: 0644]
JSTests/stress/big-int-prototype-properties.js [new file with mode: 0644]
JSTests/stress/big-int-prototype-proto.js [new file with mode: 0644]
JSTests/stress/big-int-prototype-symbol-to-string-tag.js [new file with mode: 0644]
JSTests/stress/big-int-prototype-to-string-apply.js [new file with mode: 0644]
JSTests/stress/big-int-prototype-value-of.js [new file with mode: 0644]
JSTests/stress/big-int-to-object.js [new file with mode: 0644]
JSTests/stress/big-int-to-string.js [new file with mode: 0644]
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/BigIntConstructor.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/BigIntConstructor.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/BigIntObject.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/BigIntObject.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/BigIntPrototype.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/BigIntPrototype.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSBigInt.cpp
Source/JavaScriptCore/runtime/JSBigInt.h
Source/JavaScriptCore/runtime/JSCJSValue.cpp
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/StructureCache.h
Source/JavaScriptCore/runtime/StructureInlines.h