Drop !newTarget check since it always becomes true
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Oct 2015 10:16:58 +0000 (10:16 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Oct 2015 10:16:58 +0000 (10:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150308

Reviewed by Geoffrey Garen.

In a context of calling a constructor, `newTarget` should not become JSEmpty.
So `!newTarget` always becomes true. This patch drops this unneccessary check.
And to ensure the implementation of the constructor is only called under
the context of calling it as a constructor, we change these functions to
static and only use them for constructor implementations of InternalFunction.

* runtime/IntlCollatorConstructor.cpp:
(JSC::constructIntlCollator):
(JSC::callIntlCollator):
* runtime/IntlCollatorConstructor.h:
* runtime/IntlDateTimeFormatConstructor.cpp:
(JSC::constructIntlDateTimeFormat):
(JSC::callIntlDateTimeFormat):
* runtime/IntlDateTimeFormatConstructor.h:
* runtime/IntlNumberFormatConstructor.cpp:
(JSC::constructIntlNumberFormat):
(JSC::callIntlNumberFormat):
* runtime/IntlNumberFormatConstructor.h:
* runtime/JSPromiseConstructor.cpp:
(JSC::constructPromise):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/IntlCollatorConstructor.cpp
Source/JavaScriptCore/runtime/IntlCollatorConstructor.h
Source/JavaScriptCore/runtime/IntlDateTimeFormatConstructor.cpp
Source/JavaScriptCore/runtime/IntlDateTimeFormatConstructor.h
Source/JavaScriptCore/runtime/IntlNumberFormatConstructor.cpp
Source/JavaScriptCore/runtime/IntlNumberFormatConstructor.h
Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp

index 8cbe9ed..3b4acfd 100644 (file)
@@ -1,3 +1,31 @@
+2015-10-19  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Drop !newTarget check since it always becomes true
+        https://bugs.webkit.org/show_bug.cgi?id=150308
+
+        Reviewed by Geoffrey Garen.
+
+        In a context of calling a constructor, `newTarget` should not become JSEmpty.
+        So `!newTarget` always becomes true. This patch drops this unneccessary check.
+        And to ensure the implementation of the constructor is only called under
+        the context of calling it as a constructor, we change these functions to
+        static and only use them for constructor implementations of InternalFunction.
+
+        * runtime/IntlCollatorConstructor.cpp:
+        (JSC::constructIntlCollator):
+        (JSC::callIntlCollator):
+        * runtime/IntlCollatorConstructor.h:
+        * runtime/IntlDateTimeFormatConstructor.cpp:
+        (JSC::constructIntlDateTimeFormat):
+        (JSC::callIntlDateTimeFormat):
+        * runtime/IntlDateTimeFormatConstructor.h:
+        * runtime/IntlNumberFormatConstructor.cpp:
+        (JSC::constructIntlNumberFormat):
+        (JSC::callIntlNumberFormat):
+        * runtime/IntlNumberFormatConstructor.h:
+        * runtime/JSPromiseConstructor.cpp:
+        (JSC::constructPromise):
+
 2015-10-18  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Promise constructor should throw when not called with "new"
index 0e9928f..8fca42a 100644 (file)
@@ -83,12 +83,12 @@ void IntlCollatorConstructor::finishCreation(VM& vm, IntlCollatorPrototype* coll
     m_collatorStructure.set(vm, this, collatorStructure);
 }
 
-EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState* exec)
+static EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState* exec)
 {
     // 10.1.2 Intl.Collator ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
     JSValue newTarget = exec->newTarget();
-    if (!newTarget || newTarget.isUndefined())
+    if (newTarget.isUndefined())
         newTarget = exec->callee();
 
     // 2. Let collator be OrdinaryCreateFromConstructor(newTarget, %CollatorPrototype%).
@@ -108,7 +108,7 @@ EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState* exec)
     return JSValue::encode(collator);
 }
 
-EncodedJSValue JSC_HOST_CALL callIntlCollator(ExecState* exec)
+static EncodedJSValue JSC_HOST_CALL callIntlCollator(ExecState* exec)
 {
     // 10.1.2 Intl.Collator ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
index 4aa98f2..33853a0 100644 (file)
@@ -60,9 +60,6 @@ private:
     WriteBarrier<Structure> m_collatorStructure;
 };
 
-EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState*);
-EncodedJSValue JSC_HOST_CALL callIntlCollator(ExecState*);
-
 } // namespace JSC
 
 #endif // ENABLE(INTL)
index 7283b15..f2da051 100644 (file)
@@ -84,12 +84,12 @@ void IntlDateTimeFormatConstructor::finishCreation(VM& vm, IntlDateTimeFormatPro
     m_dateTimeFormatStructure.set(vm, this, dateTimeFormatStructure);
 }
 
-EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState* exec)
+static EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState* exec)
 {
     // 12.1.2 Intl.DateTimeFormat ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
     JSValue newTarget = exec->newTarget();
-    if (!newTarget || newTarget.isUndefined())
+    if (newTarget.isUndefined())
         newTarget = exec->callee();
 
     // 2. Let dateTimeFormat be OrdinaryCreateFromConstructor(newTarget, %DateTimeFormatPrototype%).
@@ -108,8 +108,8 @@ EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState* exec)
 
     return JSValue::encode(dateTimeFormat);
 }
-    
-EncodedJSValue JSC_HOST_CALL callIntlDateTimeFormat(ExecState* exec)
+
+static EncodedJSValue JSC_HOST_CALL callIntlDateTimeFormat(ExecState* exec)
 {
     // 12.1.2 Intl.DateTimeFormat ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
index cf043a7..fd7339e 100644 (file)
@@ -60,9 +60,6 @@ private:
     WriteBarrier<Structure> m_dateTimeFormatStructure;
 };
 
-EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState*);
-EncodedJSValue JSC_HOST_CALL callIntlDateTimeFormat(ExecState*);
-
 } // namespace JSC
 
 #endif // ENABLE(INTL)
index 2429c18..04c50aa 100644 (file)
@@ -84,12 +84,12 @@ void IntlNumberFormatConstructor::finishCreation(VM& vm, IntlNumberFormatPrototy
     m_numberFormatStructure.set(vm, this, numberFormatStructure);
 }
 
-EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState* exec)
+static EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState* exec)
 {
     // 11.1.2 Intl.NumberFormat ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
     JSValue newTarget = exec->newTarget();
-    if (!newTarget || newTarget.isUndefined())
+    if (newTarget.isUndefined())
         newTarget = exec->callee();
 
     // 2. Let numberFormat be OrdinaryCreateFromConstructor(newTarget, %NumberFormatPrototype%).
@@ -109,7 +109,7 @@ EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState* exec)
     return JSValue::encode(numberFormat);
 }
 
-EncodedJSValue JSC_HOST_CALL callIntlNumberFormat(ExecState* exec)
+static EncodedJSValue JSC_HOST_CALL callIntlNumberFormat(ExecState* exec)
 {
     // 11.1.2 Intl.NumberFormat ([locales [, options]]) (ECMA-402 2.0)
     // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
index bb75f10..3f7c26a 100644 (file)
@@ -60,9 +60,6 @@ private:
     WriteBarrier<Structure> m_numberFormatStructure;
 };
 
-EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState*);
-EncodedJSValue JSC_HOST_CALL callIntlNumberFormat(ExecState*);
-
 } // namespace JSC
 
 #endif // ENABLE(INTL)
index 1e0e693..a9ba1c5 100644 (file)
@@ -90,7 +90,7 @@ static EncodedJSValue JSC_HOST_CALL constructPromise(ExecState* exec)
     VM& vm = exec->vm();
 
     JSValue newTarget = exec->newTarget();
-    if (!newTarget || newTarget.isUndefined())
+    if (newTarget.isUndefined())
         return throwVMTypeError(exec);
 
     JSPromise* promise = JSPromise::create(vm, globalObject->promiseStructure());