Skip to content

Commit b68d348

Browse files
committed
[JSC] JSWrapperObject should not be destructible
https://bugs.webkit.org/show_bug.cgi?id=194743 Reviewed by Saam Barati. JSWrapperObject should be just a wrapper object for JSValue, thus, it should not be a JSDestructibleObject. Currently it is destructible object because DateInstance uses it. This patch changes Base of DateInstance from JSWrapperObject to JSDestructibleObject, and makes JSWrapperObject non-destructible. * runtime/BigIntObject.cpp: (JSC::BigIntObject::BigIntObject): * runtime/BooleanConstructor.cpp: (JSC::BooleanConstructor::finishCreation): * runtime/BooleanObject.cpp: (JSC::BooleanObject::BooleanObject): * runtime/BooleanObject.h: * runtime/DateInstance.cpp: (JSC::DateInstance::DateInstance): (JSC::DateInstance::finishCreation): * runtime/DateInstance.h: * runtime/DatePrototype.cpp: (JSC::dateProtoFuncGetTime): (JSC::dateProtoFuncSetTime): (JSC::setNewValueFromTimeArgs): (JSC::setNewValueFromDateArgs): (JSC::dateProtoFuncSetYear): * runtime/JSCPoison.h: * runtime/JSWrapperObject.h: (JSC::JSWrapperObject::JSWrapperObject): * runtime/NumberObject.cpp: (JSC::NumberObject::NumberObject): * runtime/NumberObject.h: * runtime/StringConstructor.cpp: (JSC::StringConstructor::finishCreation): * runtime/StringObject.cpp: (JSC::StringObject::StringObject): * runtime/StringObject.h: (JSC::StringObject::internalValue const): * runtime/SymbolObject.cpp: (JSC::SymbolObject::SymbolObject): * runtime/SymbolObject.h: Canonical link: https://commits.webkit.org/209142@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241649 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9e0d02e commit b68d348

17 files changed

Lines changed: 99 additions & 63 deletions

Source/JavaScriptCore/ChangeLog

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
2019-02-16 Yusuke Suzuki <ysuzuki@apple.com>
2+
3+
[JSC] JSWrapperObject should not be destructible
4+
https://bugs.webkit.org/show_bug.cgi?id=194743
5+
6+
Reviewed by Saam Barati.
7+
8+
JSWrapperObject should be just a wrapper object for JSValue, thus, it should not be a JSDestructibleObject.
9+
Currently it is destructible object because DateInstance uses it. This patch changes Base of DateInstance from
10+
JSWrapperObject to JSDestructibleObject, and makes JSWrapperObject non-destructible.
11+
12+
* runtime/BigIntObject.cpp:
13+
(JSC::BigIntObject::BigIntObject):
14+
* runtime/BooleanConstructor.cpp:
15+
(JSC::BooleanConstructor::finishCreation):
16+
* runtime/BooleanObject.cpp:
17+
(JSC::BooleanObject::BooleanObject):
18+
* runtime/BooleanObject.h:
19+
* runtime/DateInstance.cpp:
20+
(JSC::DateInstance::DateInstance):
21+
(JSC::DateInstance::finishCreation):
22+
* runtime/DateInstance.h:
23+
* runtime/DatePrototype.cpp:
24+
(JSC::dateProtoFuncGetTime):
25+
(JSC::dateProtoFuncSetTime):
26+
(JSC::setNewValueFromTimeArgs):
27+
(JSC::setNewValueFromDateArgs):
28+
(JSC::dateProtoFuncSetYear):
29+
* runtime/JSCPoison.h:
30+
* runtime/JSWrapperObject.h:
31+
(JSC::JSWrapperObject::JSWrapperObject):
32+
* runtime/NumberObject.cpp:
33+
(JSC::NumberObject::NumberObject):
34+
* runtime/NumberObject.h:
35+
* runtime/StringConstructor.cpp:
36+
(JSC::StringConstructor::finishCreation):
37+
* runtime/StringObject.cpp:
38+
(JSC::StringObject::StringObject):
39+
* runtime/StringObject.h:
40+
(JSC::StringObject::internalValue const):
41+
* runtime/SymbolObject.cpp:
42+
(JSC::SymbolObject::SymbolObject):
43+
* runtime/SymbolObject.h:
44+
145
2019-02-16 Yusuke Suzuki <ysuzuki@apple.com>
246

347
[JSC] Shrink UnlinkedFunctionExecutable

Source/JavaScriptCore/runtime/BigIntObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ BigIntObject* BigIntObject::create(VM& vm, JSGlobalObject* globalObject, JSBigIn
4545
}
4646

4747
BigIntObject::BigIntObject(VM& vm, Structure* structure)
48-
: JSWrapperObject(vm, structure)
48+
: Base(vm, structure)
4949
{
5050
}
5151

Source/JavaScriptCore/runtime/BooleanConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure)
5757

5858
void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype)
5959
{
60-
Base::finishCreation(vm, booleanPrototype->classInfo()->className);
60+
Base::finishCreation(vm, booleanPrototype->classInfo(vm)->className);
6161
putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
6262
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
6363
}

Source/JavaScriptCore/runtime/BooleanObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ namespace JSC {
2828

2929
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanObject);
3030

31-
const ClassInfo BooleanObject::s_info = { "Boolean", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanObject) };
31+
const ClassInfo BooleanObject::s_info = { "Boolean", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanObject) };
3232

3333
BooleanObject::BooleanObject(VM& vm, Structure* structure)
34-
: JSWrapperObject(vm, structure)
34+
: Base(vm, structure)
3535
{
3636
}
3737

Source/JavaScriptCore/runtime/BooleanObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BooleanObject : public JSWrapperObject {
3030
JS_EXPORT_PRIVATE void finishCreation(VM&);
3131

3232
public:
33-
typedef JSWrapperObject Base;
33+
using Base = JSWrapperObject;
3434

3535
static BooleanObject* create(VM& vm, Structure* structure)
3636
{

Source/JavaScriptCore/runtime/DateInstance.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,24 @@ namespace JSC {
3232

3333
using namespace WTF;
3434

35-
const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(DateInstance)};
35+
const ClassInfo DateInstance::s_info = {"Date", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(DateInstance)};
3636

3737
DateInstance::DateInstance(VM& vm, Structure* structure)
38-
: JSWrapperObject(vm, structure)
38+
: Base(vm, structure)
3939
{
4040
}
4141

4242
void DateInstance::finishCreation(VM& vm)
4343
{
4444
Base::finishCreation(vm);
4545
ASSERT(inherits(vm, info()));
46-
setInternalValue(vm, jsNaN());
4746
}
4847

4948
void DateInstance::finishCreation(VM& vm, double time)
5049
{
5150
Base::finishCreation(vm);
5251
ASSERT(inherits(vm, info()));
53-
setInternalValue(vm, jsNumber(timeClip(time)));
52+
m_internalNumber = timeClip(time);
5453
}
5554

5655
void DateInstance::destroy(JSCell* cell)

Source/JavaScriptCore/runtime/DateInstance.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
#pragma once
2222

23-
#include "JSCPoison.h"
24-
#include "JSWrapperObject.h"
23+
#include "JSDestructibleObject.h"
2524

2625
namespace JSC {
2726

28-
class DateInstance final : public JSWrapperObject {
27+
class DateInstance final : public JSDestructibleObject {
2928
protected:
3029
JS_EXPORT_PRIVATE DateInstance(VM&, Structure*);
3130
void finishCreation(VM&);
@@ -34,7 +33,7 @@ class DateInstance final : public JSWrapperObject {
3433
JS_EXPORT_PRIVATE static void destroy(JSCell*);
3534

3635
public:
37-
typedef JSWrapperObject Base;
36+
using Base = JSDestructibleObject;
3837

3938
static DateInstance* create(VM& vm, Structure* structure, double date)
4039
{
@@ -50,7 +49,8 @@ class DateInstance final : public JSWrapperObject {
5049
return instance;
5150
}
5251

53-
double internalNumber() const { return internalValue().asNumber(); }
52+
double internalNumber() const { return m_internalNumber; }
53+
void setInternalNumber(double value) { m_internalNumber = value; }
5454

5555
DECLARE_EXPORT_INFO;
5656

@@ -77,7 +77,8 @@ class DateInstance final : public JSWrapperObject {
7777
JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
7878
JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
7979

80-
mutable PoisonedRefPtr<DateInstancePoison, DateInstanceData> m_data;
80+
double m_internalNumber { PNaN };
81+
mutable RefPtr<DateInstanceData> m_data;
8182
};
8283

8384
} // namespace JSC

Source/JavaScriptCore/runtime/DatePrototype.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState* exec)
648648
if (UNLIKELY(!thisDateObj))
649649
return throwVMTypeError(exec, scope);
650650

651-
return JSValue::encode(thisDateObj->internalValue());
651+
return JSValue::encode(jsNumber(thisDateObj->internalNumber()));
652652
}
653653

654654
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState* exec)
@@ -923,9 +923,8 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec)
923923

924924
double milli = timeClip(exec->argument(0).toNumber(exec));
925925
RETURN_IF_EXCEPTION(scope, encodedJSValue());
926-
JSValue result = jsNumber(milli);
927-
thisDateObj->setInternalValue(vm, result);
928-
return JSValue::encode(result);
926+
thisDateObj->setInternalNumber(milli);
927+
return JSValue::encode(jsNumber(milli));
929928
}
930929

931930
static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, WTF::TimeType inputTimeType)
@@ -940,9 +939,8 @@ static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse,
940939
double milli = thisDateObj->internalNumber();
941940

942941
if (!exec->argumentCount() || std::isnan(milli)) {
943-
JSValue result = jsNaN();
944-
thisDateObj->setInternalValue(vm, result);
945-
return JSValue::encode(result);
942+
thisDateObj->setInternalNumber(PNaN);
943+
return JSValue::encode(jsNaN());
946944
}
947945

948946
double secs = floor(milli / msPerSecond);
@@ -959,15 +957,14 @@ static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse,
959957
bool success = fillStructuresUsingTimeArgs(exec, numArgsToUse, &ms, &gregorianDateTime);
960958
RETURN_IF_EXCEPTION(scope, encodedJSValue());
961959
if (!success) {
962-
JSValue result = jsNaN();
963-
thisDateObj->setInternalValue(vm, result);
964-
return JSValue::encode(result);
960+
thisDateObj->setInternalNumber(PNaN);
961+
return JSValue::encode(jsNaN());
965962
}
966963

967964
double newUTCDate = gregorianDateTimeToMS(vm, gregorianDateTime, ms, inputTimeType);
968-
JSValue result = jsNumber(timeClip(newUTCDate));
969-
thisDateObj->setInternalValue(vm, result);
970-
return JSValue::encode(result);
965+
double result = timeClip(newUTCDate);
966+
thisDateObj->setInternalNumber(result);
967+
return JSValue::encode(jsNumber(result));
971968
}
972969

973970
static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, WTF::TimeType inputTimeType)
@@ -980,9 +977,8 @@ static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse,
980977
return throwVMTypeError(exec, scope);
981978

982979
if (!exec->argumentCount()) {
983-
JSValue result = jsNaN();
984-
thisDateObj->setInternalValue(vm, result);
985-
return JSValue::encode(result);
980+
thisDateObj->setInternalNumber(PNaN);
981+
return JSValue::encode(jsNaN());
986982
}
987983

988984
double milli = thisDateObj->internalNumber();
@@ -1004,15 +1000,14 @@ static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse,
10041000
bool success = fillStructuresUsingDateArgs(exec, numArgsToUse, &ms, &gregorianDateTime);
10051001
RETURN_IF_EXCEPTION(scope, encodedJSValue());
10061002
if (!success) {
1007-
JSValue result = jsNaN();
1008-
thisDateObj->setInternalValue(vm, result);
1009-
return JSValue::encode(result);
1003+
thisDateObj->setInternalNumber(PNaN);
1004+
return JSValue::encode(jsNaN());
10101005
}
10111006

10121007
double newUTCDate = gregorianDateTimeToMS(vm, gregorianDateTime, ms, inputTimeType);
1013-
JSValue result = jsNumber(timeClip(newUTCDate));
1014-
thisDateObj->setInternalValue(vm, result);
1015-
return JSValue::encode(result);
1008+
double result = timeClip(newUTCDate);
1009+
thisDateObj->setInternalNumber(result);
1010+
return JSValue::encode(jsNumber(result));
10161011
}
10171012

10181013
EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState* exec)
@@ -1095,9 +1090,8 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
10951090
return throwVMTypeError(exec, scope);
10961091

10971092
if (!exec->argumentCount()) {
1098-
JSValue result = jsNaN();
1099-
thisDateObj->setInternalValue(vm, result);
1100-
return JSValue::encode(result);
1093+
thisDateObj->setInternalNumber(PNaN);
1094+
return JSValue::encode(jsNaN());
11011095
}
11021096

11031097
double milli = thisDateObj->internalNumber();
@@ -1118,16 +1112,15 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
11181112
double year = exec->argument(0).toIntegerPreserveNaN(exec);
11191113
RETURN_IF_EXCEPTION(scope, encodedJSValue());
11201114
if (!std::isfinite(year)) {
1121-
JSValue result = jsNaN();
1122-
thisDateObj->setInternalValue(vm, result);
1123-
return JSValue::encode(result);
1115+
thisDateObj->setInternalNumber(PNaN);
1116+
return JSValue::encode(jsNaN());
11241117
}
11251118

11261119
gregorianDateTime.setYear(toInt32((year >= 0 && year <= 99) ? (year + 1900) : year));
11271120
double timeInMilliseconds = gregorianDateTimeToMS(vm, gregorianDateTime, ms, WTF::LocalTime);
1128-
JSValue result = jsNumber(timeClip(timeInMilliseconds));
1129-
thisDateObj->setInternalValue(vm, result);
1130-
return JSValue::encode(result);
1121+
double result = timeClip(timeInMilliseconds);
1122+
thisDateObj->setInternalNumber(result);
1123+
return JSValue::encode(jsNumber(result));
11311124
}
11321125

11331126
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec)

Source/JavaScriptCore/runtime/JSCPoison.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ namespace JSC {
3333
#define FOR_EACH_JSC_POISON(v) \
3434
v(ArrayPrototype) \
3535
v(CodeBlock) \
36-
v(DateInstance) \
3736
v(GlobalData) \
3837
v(JITCode) \
3938
v(JSAPIWrapperObject) \

Source/JavaScriptCore/runtime/JSWrapperObject.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
#pragma once
2323

24-
#include "JSDestructibleObject.h"
24+
#include "JSObject.h"
2525

2626
namespace JSC {
2727

2828
// This class is used as a base for classes such as String,
29-
// Number, Boolean and Date which are wrappers for primitive types.
30-
class JSWrapperObject : public JSDestructibleObject {
29+
// Number, Boolean and Symbol which are wrappers for primitive types.
30+
class JSWrapperObject : public JSNonFinalObject {
3131
public:
32-
typedef JSDestructibleObject Base;
32+
using Base = JSNonFinalObject;
3333

3434
static size_t allocationSize(Checked<size_t> inlineCapacity)
3535
{
@@ -65,7 +65,7 @@ class JSWrapperObject : public JSDestructibleObject {
6565
};
6666

6767
inline JSWrapperObject::JSWrapperObject(VM& vm, Structure* structure)
68-
: JSDestructibleObject(vm, structure)
68+
: Base(vm, structure)
6969
{
7070
}
7171

0 commit comments

Comments
 (0)