diff options
author | Stephan Unverwerth <s.unverwerth@gmx.de> | 2020-04-13 01:07:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-13 01:14:21 +0200 |
commit | bbd592cb6c449dd0b96b8e6a8103126d698f8262 (patch) | |
tree | 06a043c30206c7e8981aa6b6a392a49c100d9f6a /Libraries/LibJS/Runtime | |
parent | 0d41e542b70bdcd2eea6eac7dc2748bb5b1f2f79 (diff) | |
download | serenity-bbd592cb6c449dd0b96b8e6a8103126d698f8262.zip |
LibJS: Tweak FunctionPrototype::to_string and constructors
The output of FunctionPrototype::to_string is now more in line
with the output in Firefox. The builtin constructors have been
extended to include their function name in the output.
Diffstat (limited to 'Libraries/LibJS/Runtime')
-rw-r--r-- | Libraries/LibJS/Runtime/ArrayConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/BooleanConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/DateConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/ErrorConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/FunctionConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/FunctionPrototype.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/NativeFunction.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/NativeFunction.h | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/NumberConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/ObjectConstructor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/StringConstructor.cpp | 1 |
11 files changed, 19 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 6be1953fff..bfaaccd05f 100644 --- a/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -34,6 +34,7 @@ namespace JS { ArrayConstructor::ArrayConstructor() + : NativeFunction("Array") { put("prototype", interpreter().array_prototype()); put("length", Value(1)); diff --git a/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Libraries/LibJS/Runtime/BooleanConstructor.cpp index c8254abd66..3f5d54a68a 100644 --- a/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -33,6 +33,7 @@ namespace JS { BooleanConstructor::BooleanConstructor() + : NativeFunction("Boolean") { put("prototype", Value(interpreter().boolean_prototype())); put("length", Value(1)); diff --git a/Libraries/LibJS/Runtime/DateConstructor.cpp b/Libraries/LibJS/Runtime/DateConstructor.cpp index 407c95d38d..9f825a6b96 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -34,6 +34,7 @@ namespace JS { DateConstructor::DateConstructor() + : NativeFunction("Date") { put("prototype", interpreter().date_prototype()); put("length", Value(7)); diff --git a/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Libraries/LibJS/Runtime/ErrorConstructor.cpp index b62018fe02..082d3d3944 100644 --- a/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -31,6 +31,7 @@ namespace JS { ErrorConstructor::ErrorConstructor() + : NativeFunction("Error") { put("prototype", interpreter().error_prototype()); put("length", Value(1)); diff --git a/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 6a005f8324..fc93e3d13c 100644 --- a/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -35,6 +35,7 @@ namespace JS { FunctionConstructor::FunctionConstructor() + : NativeFunction("Function") { put("prototype", interpreter().function_prototype()); put("length", Value(1)); diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 33f36335af..62e6c60068 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -122,7 +122,11 @@ Value FunctionPrototype::to_string(Interpreter& interpreter) // function_body = body.to_source(); function_body = " ???"; } - auto function_source = String::format("function %s(%s) {\n%s\n}", function_name.characters(), function_parameters.characters(), function_body.characters()); + + auto function_source = String::format("function %s(%s) {\n%s\n}", + function_name.is_null() ? "" : function_name.characters(), + function_parameters.characters(), + function_body.characters()); return js_string(interpreter, function_source); } diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp index e50988105c..aadf7d8060 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -36,6 +36,11 @@ NativeFunction::NativeFunction(const FlyString& name, AK::Function<Value(Interpr { } +NativeFunction::NativeFunction(const FlyString& name) + : m_name(name) +{ +} + NativeFunction::~NativeFunction() { } diff --git a/Libraries/LibJS/Runtime/NativeFunction.h b/Libraries/LibJS/Runtime/NativeFunction.h index 8495cb7cb8..d79fb38b04 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Libraries/LibJS/Runtime/NativeFunction.h @@ -43,6 +43,7 @@ public: virtual bool has_constructor() const { return false; } protected: + NativeFunction(const FlyString& name); NativeFunction() {} private: diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp index 817a4858b0..4a5c9fc80c 100644 --- a/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -37,6 +37,7 @@ namespace JS { NumberConstructor::NumberConstructor() + : NativeFunction("Number") { put_native_function("isSafeInteger", is_safe_integer, 1); diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index ad00184707..21bd5c18b3 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -35,6 +35,7 @@ namespace JS { ObjectConstructor::ObjectConstructor() + : NativeFunction("Object") { put("prototype", interpreter().object_prototype()); diff --git a/Libraries/LibJS/Runtime/StringConstructor.cpp b/Libraries/LibJS/Runtime/StringConstructor.cpp index 5001e6ba8b..f28c89b307 100644 --- a/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -33,6 +33,7 @@ namespace JS { StringConstructor::StringConstructor() + : NativeFunction("String") { put("prototype", interpreter().string_prototype()); put("length", Value(1)); |