[JSC] JSWrapperObject should not be destructible
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Feb 2019 18:50:08 +0000 (18:50 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Feb 2019 18:50:08 +0000 (18:50 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241649 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/BigIntObject.cpp
Source/JavaScriptCore/runtime/BooleanConstructor.cpp
Source/JavaScriptCore/runtime/BooleanObject.cpp
Source/JavaScriptCore/runtime/BooleanObject.h
Source/JavaScriptCore/runtime/DateInstance.cpp
Source/JavaScriptCore/runtime/DateInstance.h
Source/JavaScriptCore/runtime/DatePrototype.cpp
Source/JavaScriptCore/runtime/JSCPoison.h
Source/JavaScriptCore/runtime/JSWrapperObject.h
Source/JavaScriptCore/runtime/NumberObject.cpp
Source/JavaScriptCore/runtime/NumberObject.h
Source/JavaScriptCore/runtime/StringConstructor.cpp
Source/JavaScriptCore/runtime/StringObject.cpp
Source/JavaScriptCore/runtime/StringObject.h
Source/JavaScriptCore/runtime/SymbolObject.cpp
Source/JavaScriptCore/runtime/SymbolObject.h

index 13b3cd5..4a261f1 100644 (file)
@@ -1,5 +1,49 @@
 2019-02-16  Yusuke Suzuki  <ysuzuki@apple.com>
 
+        [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:
+
+2019-02-16  Yusuke Suzuki  <ysuzuki@apple.com>
+
         [JSC] Shrink UnlinkedFunctionExecutable
         https://bugs.webkit.org/show_bug.cgi?id=194733
 
index 1f04547..3c14982 100644 (file)
@@ -45,7 +45,7 @@ BigIntObject* BigIntObject::create(VM& vm, JSGlobalObject* globalObject, JSBigIn
 }
 
 BigIntObject::BigIntObject(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index b8fa66c..e32378f 100644 (file)
@@ -57,7 +57,7 @@ BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure)
 
 void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype)
 {
-    Base::finishCreation(vm, booleanPrototype->classInfo()->className);
+    Base::finishCreation(vm, booleanPrototype->classInfo(vm)->className);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
     putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
index b64b033..7de5deb 100644 (file)
@@ -28,10 +28,10 @@ namespace JSC {
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanObject);
 
-const ClassInfo BooleanObject::s_info = { "Boolean", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanObject) };
+const ClassInfo BooleanObject::s_info = { "Boolean", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanObject) };
 
 BooleanObject::BooleanObject(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index 27c43e7..85d673c 100644 (file)
@@ -30,7 +30,7 @@ protected:
     JS_EXPORT_PRIVATE void finishCreation(VM&);
 
 public:
-    typedef JSWrapperObject Base;
+    using Base = JSWrapperObject;
 
     static BooleanObject* create(VM& vm, Structure* structure)
     {
index 4dd8603..9e2dd20 100644 (file)
@@ -32,10 +32,10 @@ namespace JSC {
 
 using namespace WTF;
 
-const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(DateInstance)};
+const ClassInfo DateInstance::s_info = {"Date", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(DateInstance)};
 
 DateInstance::DateInstance(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
@@ -43,14 +43,13 @@ void DateInstance::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
     ASSERT(inherits(vm, info()));
-    setInternalValue(vm, jsNaN());
 }
 
 void DateInstance::finishCreation(VM& vm, double time)
 {
     Base::finishCreation(vm);
     ASSERT(inherits(vm, info()));
-    setInternalValue(vm, jsNumber(timeClip(time)));
+    m_internalNumber = timeClip(time);
 }
 
 void DateInstance::destroy(JSCell* cell)
index 4630cfd..cad748d 100644 (file)
 
 #pragma once
 
-#include "JSCPoison.h"
-#include "JSWrapperObject.h"
+#include "JSDestructibleObject.h"
 
 namespace JSC {
 
-class DateInstance final : public JSWrapperObject {
+class DateInstance final : public JSDestructibleObject {
 protected:
     JS_EXPORT_PRIVATE DateInstance(VM&, Structure*);
     void finishCreation(VM&);
@@ -34,7 +33,7 @@ protected:
     JS_EXPORT_PRIVATE static void destroy(JSCell*);
 
 public:
-    typedef JSWrapperObject Base;
+    using Base = JSDestructibleObject;
 
     static DateInstance* create(VM& vm, Structure* structure, double date)
     {
@@ -50,7 +49,8 @@ public:
         return instance;
     }
 
-    double internalNumber() const { return internalValue().asNumber(); }
+    double internalNumber() const { return m_internalNumber; }
+    void setInternalNumber(double value) { m_internalNumber = value; }
 
     DECLARE_EXPORT_INFO;
 
@@ -77,7 +77,8 @@ private:
     JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
     JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
 
-    mutable PoisonedRefPtr<DateInstancePoison, DateInstanceData> m_data;
+    double m_internalNumber { PNaN };
+    mutable RefPtr<DateInstanceData> m_data;
 };
 
 } // namespace JSC
index 71edba9..fbd0975 100644 (file)
@@ -648,7 +648,7 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState* exec)
     if (UNLIKELY(!thisDateObj))
         return throwVMTypeError(exec, scope);
 
-    return JSValue::encode(thisDateObj->internalValue());
+    return JSValue::encode(jsNumber(thisDateObj->internalNumber()));
 }
 
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState* exec)
@@ -923,9 +923,8 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec)
 
     double milli = timeClip(exec->argument(0).toNumber(exec));
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    JSValue result = jsNumber(milli);
-    thisDateObj->setInternalValue(vm, result);
-    return JSValue::encode(result);
+    thisDateObj->setInternalNumber(milli);
+    return JSValue::encode(jsNumber(milli));
 }
 
 static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, WTF::TimeType inputTimeType)
@@ -940,9 +939,8 @@ static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse,
     double milli = thisDateObj->internalNumber();
 
     if (!exec->argumentCount() || std::isnan(milli)) {
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     }
      
     double secs = floor(milli / msPerSecond);
@@ -959,15 +957,14 @@ static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse,
     bool success = fillStructuresUsingTimeArgs(exec, numArgsToUse, &ms, &gregorianDateTime);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
     if (!success) {
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     } 
 
     double newUTCDate = gregorianDateTimeToMS(vm, gregorianDateTime, ms, inputTimeType);
-    JSValue result = jsNumber(timeClip(newUTCDate));
-    thisDateObj->setInternalValue(vm, result);
-    return JSValue::encode(result);
+    double result = timeClip(newUTCDate);
+    thisDateObj->setInternalNumber(result);
+    return JSValue::encode(jsNumber(result));
 }
 
 static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, WTF::TimeType inputTimeType)
@@ -980,9 +977,8 @@ static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse,
         return throwVMTypeError(exec, scope);
 
     if (!exec->argumentCount()) {
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     }
 
     double milli = thisDateObj->internalNumber();
@@ -1004,15 +1000,14 @@ static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse,
     bool success = fillStructuresUsingDateArgs(exec, numArgsToUse, &ms, &gregorianDateTime);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
     if (!success) {
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     } 
 
     double newUTCDate = gregorianDateTimeToMS(vm, gregorianDateTime, ms, inputTimeType);
-    JSValue result = jsNumber(timeClip(newUTCDate));
-    thisDateObj->setInternalValue(vm, result);
-    return JSValue::encode(result);
+    double result = timeClip(newUTCDate);
+    thisDateObj->setInternalNumber(result);
+    return JSValue::encode(jsNumber(result));
 }
 
 EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState* exec)
@@ -1095,9 +1090,8 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
         return throwVMTypeError(exec, scope);
 
     if (!exec->argumentCount()) { 
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     }
 
     double milli = thisDateObj->internalNumber();
@@ -1118,16 +1112,15 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
     double year = exec->argument(0).toIntegerPreserveNaN(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
     if (!std::isfinite(year)) {
-        JSValue result = jsNaN();
-        thisDateObj->setInternalValue(vm, result);
-        return JSValue::encode(result);
+        thisDateObj->setInternalNumber(PNaN);
+        return JSValue::encode(jsNaN());
     }
 
     gregorianDateTime.setYear(toInt32((year >= 0 && year <= 99) ? (year + 1900) : year));
     double timeInMilliseconds = gregorianDateTimeToMS(vm, gregorianDateTime, ms, WTF::LocalTime);
-    JSValue result = jsNumber(timeClip(timeInMilliseconds));
-    thisDateObj->setInternalValue(vm, result);
-    return JSValue::encode(result);
+    double result = timeClip(timeInMilliseconds);
+    thisDateObj->setInternalNumber(result);
+    return JSValue::encode(jsNumber(result));
 }
 
 EncodedJSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec)
index 1db4ac6..65cf192 100644 (file)
@@ -33,7 +33,6 @@ namespace JSC {
 #define FOR_EACH_JSC_POISON(v) \
     v(ArrayPrototype) \
     v(CodeBlock) \
-    v(DateInstance) \
     v(GlobalData) \
     v(JITCode) \
     v(JSAPIWrapperObject) \
index 211f8f8..9117fdb 100644 (file)
 
 #pragma once
 
-#include "JSDestructibleObject.h"
+#include "JSObject.h"
 
 namespace JSC {
 
 // This class is used as a base for classes such as String,
-// Number, Boolean and Date which are wrappers for primitive types.
-class JSWrapperObject : public JSDestructibleObject {
+// Number, Boolean and Symbol which are wrappers for primitive types.
+class JSWrapperObject : public JSNonFinalObject {
 public:
-    typedef JSDestructibleObject Base;
+    using Base = JSNonFinalObject;
 
     static size_t allocationSize(Checked<size_t> inlineCapacity)
     {
@@ -65,7 +65,7 @@ private:
 };
 
 inline JSWrapperObject::JSWrapperObject(VM& vm, Structure* structure)
-    : JSDestructibleObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index b76e247..411ca22 100644 (file)
@@ -30,10 +30,10 @@ namespace JSC {
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberObject);
 
-const ClassInfo NumberObject::s_info = { "Number", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NumberObject) };
+const ClassInfo NumberObject::s_info = { "Number", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NumberObject) };
 
 NumberObject::NumberObject(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index 9779fcb..17f0e57 100644 (file)
@@ -30,7 +30,7 @@ protected:
     void finishCreation(VM&);
 
 public:
-    typedef JSWrapperObject Base;
+    using Base = JSWrapperObject;
 
     static NumberObject* create(VM& vm, Structure* structure)
     {
index 12e2c30..cf5b8a8 100644 (file)
@@ -63,7 +63,7 @@ StringConstructor::StringConstructor(VM& vm, Structure* structure)
 
 void StringConstructor::finishCreation(VM& vm, StringPrototype* stringPrototype)
 {
-    Base::finishCreation(vm, stringPrototype->classInfo()->className);
+    Base::finishCreation(vm, stringPrototype->classInfo(vm)->className);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, stringPrototype, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
     putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
index 980c072..8c6ffa7 100644 (file)
@@ -30,10 +30,10 @@ namespace JSC {
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(StringObject);
 
-const ClassInfo StringObject::s_info = { "String", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(StringObject) };
+const ClassInfo StringObject::s_info = { "String", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(StringObject) };
 
 StringObject::StringObject(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index 86a0fab..8aedca6 100644 (file)
@@ -27,7 +27,7 @@ namespace JSC {
 
 class StringObject : public JSWrapperObject {
 public:
-    typedef JSWrapperObject Base;
+    using Base = JSWrapperObject;
     static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesGetPropertyNames;
 
     static StringObject* create(VM& vm, Structure* structure)
@@ -59,7 +59,7 @@ public:
 
     DECLARE_EXPORT_INFO;
 
-    JSString* internalValue() const { return asString(JSWrapperObject::internalValue());}
+    JSString* internalValue() const { return asString(JSWrapperObject::internalValue()); }
 
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
index 767bf65..3076d2e 100644 (file)
@@ -33,10 +33,10 @@ namespace JSC {
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(SymbolObject);
 
-const ClassInfo SymbolObject::s_info = { "Symbol", &JSWrapperObject::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(SymbolObject) };
+const ClassInfo SymbolObject::s_info = { "Symbol", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(SymbolObject) };
 
 SymbolObject::SymbolObject(VM& vm, Structure* structure)
-    : JSWrapperObject(vm, structure)
+    : Base(vm, structure)
 {
 }
 
index a8477f5..82de09e 100644 (file)
@@ -28,7 +28,7 @@ namespace JSC {
 
 class SymbolObject final : public JSWrapperObject {
 public:
-    typedef JSWrapperObject Base;
+    using Base = JSWrapperObject;
 
     static SymbolObject* create(VM& vm, Structure* structure)
     {