haikuwebkit/LayoutTests/js/object-literal-methods-expe...

83 lines
4.6 KiB
Plaintext
Raw Permalink Normal View History

basic tests for object literal methods
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS o = { foo() { return 10; } }; did not throw exception.
PASS o.foo() is 10
PASS typeof o.foo is 'function'
PASS o.foo.length is 0
PASS o.foo.name is 'foo'
ES6: Object Literal Methods toString is missing method name https://bugs.webkit.org/show_bug.cgi?id=142992 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-03-24 Reviewed by Geoffrey Garen. Source/JavaScriptCore: Always stringify functions in the pattern: "function " + <function name> + <text from opening parenthesis to closing brace>. * runtime/FunctionPrototype.cpp: (JSC::functionProtoFuncToString): Update the path that was not stringifying in this pattern. * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedCodeBlock.h: (JSC::UnlinkedFunctionExecutable::parametersStartOffset): * parser/Nodes.h: * runtime/Executable.cpp: (JSC::FunctionExecutable::FunctionExecutable): * runtime/Executable.h: (JSC::FunctionExecutable::parametersStartOffset): Pass the already known function parameter opening parenthesis start offset through to the FunctionExecutable. * tests/mozilla/js1_5/Scope/regress-185485.js: (with.g): Add back original space in this test that was removed by r181810 now that we have the space again in stringification. LayoutTests: * js/class-syntax-default-constructor-expected.txt: This test was already failing, it now fails in a different way. * js/object-literal-computed-methods-expected.txt: * js/object-literal-methods-expected.txt: These tests now pass. * fast/dom/TreeWalker/acceptNode-filter-expected.txt: * js/destructuring-assignment-expected.txt: * js/dfg-redundant-load-of-captured-variable-proven-constant-expected.txt: * js/dfg-resolve-global-specific-dictionary-expected.txt: * js/dom/JSON-parse-expected.txt: * js/dom/JSON-stringify-expected.txt: * js/dom/dfg-strcat-over-objects-then-exit-on-it-expected.txt: * js/dom/function-prototype-expected.txt: * js/dom/toString-and-valueOf-override-expected.txt: * js/kde/lval-exceptions-expected.txt: * storage/domstorage/localstorage/string-conversion-expected.txt: * storage/domstorage/sessionstorage/string-conversion-expected.txt: * js/dom/script-tests/dfg-strcat-over-objects-then-exit-on-it.js: * js/script-tests/dfg-redundant-load-of-captured-variable-proven-constant.js: * js/script-tests/dfg-resolve-global-specific-dictionary.js: * js/dom/function-prototype.html: Update tests to add expected whitespace for stringifying a function with no name. Canonical link: https://commits.webkit.org/161029@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181901 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-24 20:07:26 +00:00
PASS o.foo.toString() is 'function foo() { return 10; }'
PASS Object.getOwnPropertyDescriptor(o, 'foo').value is o.foo
PASS Object.getOwnPropertyDescriptor(o, 'foo').enumerable is true
PASS Object.getOwnPropertyDescriptor(o, 'foo').configurable is true
PASS Object.getOwnPropertyDescriptor(o, 'foo').writable is true
PASS o = { add(x, y) { return x + y; } }; did not throw exception.
PASS o.add(42, -10) is 32
PASS typeof o.add is 'function'
PASS o.add.length is 2
PASS o.add.name is 'add'
ES6: Object Literal Methods toString is missing method name https://bugs.webkit.org/show_bug.cgi?id=142992 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-03-24 Reviewed by Geoffrey Garen. Source/JavaScriptCore: Always stringify functions in the pattern: "function " + <function name> + <text from opening parenthesis to closing brace>. * runtime/FunctionPrototype.cpp: (JSC::functionProtoFuncToString): Update the path that was not stringifying in this pattern. * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedCodeBlock.h: (JSC::UnlinkedFunctionExecutable::parametersStartOffset): * parser/Nodes.h: * runtime/Executable.cpp: (JSC::FunctionExecutable::FunctionExecutable): * runtime/Executable.h: (JSC::FunctionExecutable::parametersStartOffset): Pass the already known function parameter opening parenthesis start offset through to the FunctionExecutable. * tests/mozilla/js1_5/Scope/regress-185485.js: (with.g): Add back original space in this test that was removed by r181810 now that we have the space again in stringification. LayoutTests: * js/class-syntax-default-constructor-expected.txt: This test was already failing, it now fails in a different way. * js/object-literal-computed-methods-expected.txt: * js/object-literal-methods-expected.txt: These tests now pass. * fast/dom/TreeWalker/acceptNode-filter-expected.txt: * js/destructuring-assignment-expected.txt: * js/dfg-redundant-load-of-captured-variable-proven-constant-expected.txt: * js/dfg-resolve-global-specific-dictionary-expected.txt: * js/dom/JSON-parse-expected.txt: * js/dom/JSON-stringify-expected.txt: * js/dom/dfg-strcat-over-objects-then-exit-on-it-expected.txt: * js/dom/function-prototype-expected.txt: * js/dom/toString-and-valueOf-override-expected.txt: * js/kde/lval-exceptions-expected.txt: * storage/domstorage/localstorage/string-conversion-expected.txt: * storage/domstorage/sessionstorage/string-conversion-expected.txt: * js/dom/script-tests/dfg-strcat-over-objects-then-exit-on-it.js: * js/script-tests/dfg-redundant-load-of-captured-variable-proven-constant.js: * js/script-tests/dfg-resolve-global-specific-dictionary.js: * js/dom/function-prototype.html: Update tests to add expected whitespace for stringifying a function with no name. Canonical link: https://commits.webkit.org/161029@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181901 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-24 20:07:26 +00:00
PASS o.add.toString() is 'function add(x, y) { return x + y; }'
PASS o = { 'add'(a, b, c) { return a + b + c; } }; did not throw exception.
PASS o.add(1, 2, 3) is 6
PASS o = { 'a(d)d'(a, b, c) { return a + b + c; } }; did not throw exception.
PASS o['a(d)d'](1, 2, 3) is 6
PASS o = { 100() { return 100; } }; did not throw exception.
PASS o[100]() is 100
PASS o['100']() is 100
PASS o = { 100.100() { return 100.100; } }; did not throw exception.
PASS o[100.1]() is 100.1
PASS o['100.1']() is 100.1
PASS o = { 1e3() { return 1e3; } }; did not throw exception.
PASS o[1e3]() is 1000
PASS o['1000']() is 1000
PASS o = { 0x11() { return 0x11; } }; did not throw exception.
PASS o[0x11]() is 17
PASS o['17']() is 17
PASS o = { add([x, y]) { return x + y; } }; did not throw exception.
PASS o.add([142, -100]) is 42
PASS o = { foo() { return 10; }, }; did not throw exception.
PASS o = { foo ( ) { return 10; } }; did not throw exception.
PASS o = {true(){return true;}}; did not throw exception.
PASS o = {NaN(){return NaN;}}; did not throw exception.
PASS o = {eval(){return eval;}}; did not throw exception.
PASS o = { a:1, foo() { return 10; }, bar() { return 20; }, b: 2 }; did not throw exception.
PASS o = { a:1, foo() { return 10; }, bar() { return 20; }, b }; did not throw exception.
PASS o = { a:1, foo() { return 10; }, b: b, bar() { return 20; }, c: 2 }; did not throw exception.
PASS o = { a:1, foo() { return 10; }, b, bar() { return 20; }, c }; did not throw exception.
PASS o = {inner:{method(){ return 100; }}}; did not throw exception.
PASS o.inner.method() is 100
PASS o = { foo() { return 10; }, foo() { return 20; } }; did not throw exception.
PASS o.foo() is 20
PASS o = { get(x, y) { return x + y; } }; did not throw exception.
PASS o.get('hello', 'world') is 'helloworld'
PASS o = { set(x, y) { return x + y; } }; did not throw exception.
PASS o.set('hello', 'world') is 'helloworld'
PASS ({get x(){ return true; }}).x is true
PASS ({get 'x'(){ return true; }}).x is true
PASS ({get 42(){ return true; }})['42'] is true
PASS !!Object.getOwnPropertyDescriptor({set x(value){}}, 'x').set is true
PASS !!Object.getOwnPropertyDescriptor({set 'x'(value){}}, 'x').set is true
PASS !!Object.getOwnPropertyDescriptor({set 42(value){}}, '42').set is true
PASS ({ (){} }) threw exception SyntaxError: Unexpected token '('. Expected a property name..
PASS ({ foo(,,,){} }) threw exception SyntaxError: Unexpected token ','. Expected a parameter pattern or a ')' in parameter list..
PASS ({ foo(a{}, bar(){} }) threw exception SyntaxError: Unexpected token '{'. Expected a ')' or a ',' after a parameter declaration..
PASS ({ foo(a, b), bar(){} }) threw exception SyntaxError: Unexpected token ','. Expected an opening '{' at the start of a method body..
PASS ({ foo(a, b) { if }, bar(){} }) threw exception SyntaxError: Unexpected token '}'. Expected '(' to start an 'if' condition..
PASS ({__proto__: function(){}}) instanceof Function is true
PASS ({__proto__(){}}) instanceof Function is false
PASS ({__proto__(){}}).__proto__ instanceof Function is true
super should be available in object literals https://bugs.webkit.org/show_bug.cgi?id=156933 Reviewed by Saam Barati. Source/JavaScriptCore: When we originally implemented classes, super seemed to be a class-only feature. But the final spec says it's available in object literals too. * bytecompiler/NodesCodegen.cpp: (JSC::PropertyListNode::emitBytecode): Having 'super' and being a class property are no longer synonymous, so we track two separate variables. (JSC::PropertyListNode::emitPutConstantProperty): Being inside the super branch no longer guarantees that you're a class property, so we decide our attributes and our function name dynamically. * parser/ASTBuilder.h: (JSC::ASTBuilder::createArrowFunctionExpr): (JSC::ASTBuilder::createGetterOrSetterProperty): (JSC::ASTBuilder::createArguments): (JSC::ASTBuilder::createArgumentsList): (JSC::ASTBuilder::createProperty): (JSC::ASTBuilder::createPropertyList): Pass through state to indicate whether we're a class property, since we can't infer it from 'super' anymore. * parser/NodeConstructors.h: (JSC::PropertyNode::PropertyNode): See ASTBuilder.h. * parser/Nodes.h: (JSC::PropertyNode::expressionName): (JSC::PropertyNode::name): (JSC::PropertyNode::type): (JSC::PropertyNode::needsSuperBinding): (JSC::PropertyNode::isClassProperty): (JSC::PropertyNode::putType): See ASTBuilder.h. * parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseProperty): (JSC::Parser<LexerType>::parsePropertyMethod): (JSC::Parser<LexerType>::parseGetterSetter): (JSC::Parser<LexerType>::parseMemberExpression): I made these error messages generic because it is no longer practical to say concise things about the list of places you can use super. * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createArgumentsList): (JSC::SyntaxChecker::createProperty): (JSC::SyntaxChecker::appendExportSpecifier): (JSC::SyntaxChecker::appendConstDecl): (JSC::SyntaxChecker::createGetterOrSetterProperty): Updated for interface change. * tests/stress/generator-with-super.js: (test): * tests/stress/modules-syntax-error.js: * tests/stress/super-in-lexical-scope.js: (testSyntaxError): (testSyntaxError.test): * tests/stress/tagged-templates-syntax.js: Updated for error message changes. See Parser.cpp. LayoutTests: Updated expected results and added a few new tests. * js/arrowfunction-syntax-errors-expected.txt: * js/class-syntax-super-expected.txt: * js/object-literal-methods-expected.txt: * js/script-tests/arrowfunction-syntax-errors.js: * js/script-tests/class-syntax-super.js: * js/script-tests/object-literal-methods.js: Canonical link: https://commits.webkit.org/175044@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199927 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-22 23:04:55 +00:00
PASS { f() { return super.f(); } }.f() threw exception SyntaxError: Unexpected token '{'.
PASS new ({ f() { return super(); }.f) threw exception SyntaxError: super is not valid in this context..
PASS o = { f() { } }; new ({ __proto__: o, f() { return super(); } }).f threw exception SyntaxError: super is not valid in this context..
PASS ({ f() { return (() => super.f())(); } }).f() threw exception TypeError: super.f is not a function. (In 'super.f()', 'super.f' is undefined).
PASS o = { f() { return true; } }; ({ __proto__: o, f() { return super.f(); } }).f() is true
PASS o = { get p() { return true; } }; ({ __proto__: o, get p() { return super.p; } }).p is true
PASS o = { set p(p2) { } }; ({ __proto__: o, set p(p2) { super.p = p2; } }).p = true is true
PASS o = { f() { return true; } }; ({ __proto__: o, f() { return (() => super.f())(); } }).f() is true
PASS successfullyParsed is true
TEST COMPLETE