blob: 1ce0dbdd1c08f441ac991f2f263280f153070a32 [file] [log] [blame]
basic tests for object literal computed methods
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS o = { ['f'+'oo']() { 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'
PASS o.foo.toString() is 'function () { 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 methodName = 'add'; o = { [methodName](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'
PASS o.add.toString() is 'function (x, y) { return x + y; }'
PASS o = { [ (function() { return 'method'; })() ](x, y) { return x + y; } }; did not throw exception.
PASS o.method(142, -10) is 132
PASS o = { [10*10]() { return 100; } }; did not throw exception.
PASS o[100]() is 100
PASS o['100']() is 100
PASS o = { [100 + 0.100]() { return 100.100; } }; did not throw exception.
PASS o[100.1]() is 100.1
PASS o['100.1']() is 100.1
PASS o = { ['a' + 'dd']([x, y]) { return x + y; } }; did not throw exception.
PASS o.add([142, -100]) is 42
PASS o = { [Array]([x, y]) { return x + y; } }; did not throw exception.
PASS o[Array.toString()]([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 = {[foo]:{[bar](){ return 100; }}}; did not throw exception.
PASS o.foo.bar() 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 ({ [](,,,){} }) threw exception SyntaxError: Unexpected token ']'.
PASS ({ [1+](){} }) threw exception SyntaxError: Unexpected token ']'.
PASS ({ [1,](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({ [1,'name'](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({ [[1](){} }) threw exception SyntaxError: Unexpected token '{'. Expected ']' to end a computed 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
PASS successfullyParsed is true
TEST COMPLETE