new Date(NaN).toJSON() must return null instead of throwing a TypeError
[WebKit-https.git] / Source / JavaScriptCore / runtime / DatePrototype.cpp
index 77db102..fe87479 100644 (file)
@@ -1072,7 +1072,13 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec)
     JSObject* object = jsCast<JSObject*>(thisValue.toThis(exec, NotStrictMode));
     if (exec->hadException())
         return JSValue::encode(jsNull());
-    
+
+    JSValue timeValue = object->toPrimitive(exec, PreferNumber);
+    if (exec->hadException())
+        return JSValue::encode(jsNull());
+    if (timeValue.isNumber() && !(timeValue.isInt32() || std::isfinite(timeValue.asDouble())))
+        return JSValue::encode(jsNull());
+
     JSValue toISOValue = object->get(exec, exec->vm().propertyNames->toISOString);
     if (exec->hadException())
         return JSValue::encode(jsNull());