https://bugs.webkit.org/show_bug.cgi?id=147383
Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-07-28
Reviewed by Andreas Kling.
Source/JavaScriptCore:
* runtime/JSONObject.cpp:
(JSC::Stringifier::toJSON):
(JSC::Stringifier::toJSONImpl):
LayoutTests:
Make the fast case of Stringifier::toJSON() inline and the uncommon
case out-of-line.
* js/dom/JSON-stringify-string-object-with-tojson-expected.txt: Added.
* js/dom/JSON-stringify-string-object-with-tojson.html: Added.
* js/resources/JSON-stringify-string-object-with-tojson.js: Added.
(stringObject.toJSON):
(String.prototype.toJSON):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187537
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-07-28 Benjamin Poulain <bpoulain@apple.com>
+
+ Speed up the Stringifier::toJSON() fast case
+ https://bugs.webkit.org/show_bug.cgi?id=147383
+
+ Reviewed by Andreas Kling.
+
+ Make the fast case of Stringifier::toJSON() inline and the uncommon
+ case out-of-line.
+
+ * js/dom/JSON-stringify-string-object-with-tojson-expected.txt: Added.
+ * js/dom/JSON-stringify-string-object-with-tojson.html: Added.
+ * js/resources/JSON-stringify-string-object-with-tojson.js: Added.
+ (stringObject.toJSON):
+ (String.prototype.toJSON):
+
2015-07-28 Simon Fraser <simon.fraser@apple.com>
Animations sometimes fail to start
--- /dev/null
+PASS nativeJSON.stringify(stringObject) is "\"Foo\""
+PASS nativeJSON.stringify(stringObject) is JSON.stringify(stringObject)
+PASS nativeJSON.stringify(stringObject) is "\"Weird Case 1\""
+PASS nativeJSON.stringify(stringObject) is JSON.stringify(stringObject)
+PASS nativeJSON.stringify(stringObject) is "\"Bar\""
+PASS nativeJSON.stringify(stringObject) is JSON.stringify(stringObject)
+PASS nativeJSON.stringify(stringObject) is "\"Weird Case 2\""
+PASS nativeJSON.stringify(stringObject) is JSON.stringify(stringObject)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+var nativeJSON = this.JSON;
+this.JSON = null;
+</script>
+<script src="../resources/json2-es5-compat.js"></script>
+<script src="../resources/JSON-stringify-string-object-with-tojson.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+var stringObject = new String("Foo");
+shouldBeEqualToString('nativeJSON.stringify(stringObject)', '"Foo"');
+shouldBe('nativeJSON.stringify(stringObject)', 'JSON.stringify(stringObject)');
+
+stringObject.toJSON = function() { return "Weird Case 1"; }
+shouldBeEqualToString('nativeJSON.stringify(stringObject)', '"Weird Case 1"');
+shouldBe('nativeJSON.stringify(stringObject)', 'JSON.stringify(stringObject)');
+
+var stringObject = new String("Bar");
+shouldBeEqualToString('nativeJSON.stringify(stringObject)', '"Bar"');
+shouldBe('nativeJSON.stringify(stringObject)', 'JSON.stringify(stringObject)');
+
+String.prototype.toJSON = function() { return "Weird Case 2"; }
+shouldBeEqualToString('nativeJSON.stringify(stringObject)', '"Weird Case 2"');
+shouldBe('nativeJSON.stringify(stringObject)', 'JSON.stringify(stringObject)');
\ No newline at end of file
+2015-07-28 Benjamin Poulain <bpoulain@apple.com>
+
+ Speed up the Stringifier::toJSON() fast case
+ https://bugs.webkit.org/show_bug.cgi?id=147383
+
+ Reviewed by Andreas Kling.
+
+ * runtime/JSONObject.cpp:
+ (JSC::Stringifier::toJSON):
+ (JSC::Stringifier::toJSONImpl):
+
2015-07-28 Sukolsak Sakshuwong <sukolsak@gmail.com>
Implement WebAssembly module parser
friend class Holder;
JSValue toJSON(JSValue, const PropertyNameForFunctionCall&);
+ JSValue toJSONImpl(JSValue, const PropertyNameForFunctionCall&);
enum StringifyResult { StringifyFailed, StringifySucceeded, StringifyFailedDueToUndefinedValue };
StringifyResult appendStringifiedValue(StringBuilder&, JSValue, JSObject* holder, const PropertyNameForFunctionCall&);
return Local<Unknown>(m_exec->vm(), jsString(m_exec, result.toString()));
}
-inline JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionCall& propertyName)
+ALWAYS_INLINE JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionCall& propertyName)
{
ASSERT(!m_exec->hadException());
if (!value.isObject() || !asObject(value)->hasProperty(m_exec, m_exec->vm().propertyNames->toJSON))
return value;
+ return toJSONImpl(value, propertyName);
+}
+JSValue Stringifier::toJSONImpl(JSValue value, const PropertyNameForFunctionCall& propertyName)
+{
JSValue toJSONFunction = asObject(value)->get(m_exec, m_exec->vm().propertyNames->toJSON);
if (m_exec->hadException())
return jsNull();