Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 329413002: Throw syntax error when a getter/setter has the wrong number of params (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test exception Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.cc ('k') | test/mozilla/mozilla.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 2223
2224 TEST(ErrorsObjectLiteralChecking) { 2224 TEST(ErrorsObjectLiteralChecking) {
2225 const char* context_data[][2] = { 2225 const char* context_data[][2] = {
2226 {"\"use strict\"; var myobject = {", "};"}, 2226 {"\"use strict\"; var myobject = {", "};"},
2227 {"var myobject = {", "};"}, 2227 {"var myobject = {", "};"},
2228 { NULL, NULL } 2228 { NULL, NULL }
2229 }; 2229 };
2230 2230
2231 const char* statement_data[] = { 2231 const char* statement_data[] = {
2232 "foo: 1, get foo() {}", 2232 "foo: 1, get foo() {}",
2233 "foo: 1, set foo() {}", 2233 "foo: 1, set foo(v) {}",
2234 "\"foo\": 1, get \"foo\"() {}", 2234 "\"foo\": 1, get \"foo\"() {}",
2235 "\"foo\": 1, set \"foo\"() {}", 2235 "\"foo\": 1, set \"foo\"(v) {}",
2236 "1: 1, get 1() {}", 2236 "1: 1, get 1() {}",
2237 "1: 1, set 1() {}", 2237 "1: 1, set 1() {}",
2238 // It's counter-intuitive, but these collide too (even in classic 2238 // It's counter-intuitive, but these collide too (even in classic
2239 // mode). Note that we can have "foo" and foo as properties in classic mode, 2239 // mode). Note that we can have "foo" and foo as properties in classic mode,
2240 // but we cannot have "foo" and get foo, or foo and get "foo". 2240 // but we cannot have "foo" and get foo, or foo and get "foo".
2241 "foo: 1, get \"foo\"() {}", 2241 "foo: 1, get \"foo\"() {}",
2242 "foo: 1, set \"foo\"() {}", 2242 "foo: 1, set \"foo\"(v) {}",
2243 "\"foo\": 1, get foo() {}", 2243 "\"foo\": 1, get foo() {}",
2244 "\"foo\": 1, set foo() {}", 2244 "\"foo\": 1, set foo(v) {}",
2245 "1: 1, get \"1\"() {}", 2245 "1: 1, get \"1\"() {}",
2246 "1: 1, set \"1\"() {}", 2246 "1: 1, set \"1\"() {}",
2247 "\"1\": 1, get 1() {}" 2247 "\"1\": 1, get 1() {}"
2248 "\"1\": 1, set 1() {}" 2248 "\"1\": 1, set 1(v) {}"
2249 // Wrong number of parameters
2250 "get bar(x) {}",
2251 "get bar(x, y) {}",
2252 "set bar() {}",
2253 "set bar(x, y) {}",
2249 // Parsing FunctionLiteral for getter or setter fails 2254 // Parsing FunctionLiteral for getter or setter fails
2250 "get foo( +", 2255 "get foo( +",
2251 "get foo() \"error\"", 2256 "get foo() \"error\"",
2252 NULL 2257 NULL
2253 }; 2258 };
2254 2259
2255 RunParserSyncTest(context_data, statement_data, kError); 2260 RunParserSyncTest(context_data, statement_data, kError);
2256 } 2261 }
2257 2262
2258 2263
2259 TEST(NoErrorsObjectLiteralChecking) { 2264 TEST(NoErrorsObjectLiteralChecking) {
2260 const char* context_data[][2] = { 2265 const char* context_data[][2] = {
2261 {"var myobject = {", "};"}, 2266 {"var myobject = {", "};"},
2262 {"\"use strict\"; var myobject = {", "};"}, 2267 {"\"use strict\"; var myobject = {", "};"},
2263 { NULL, NULL } 2268 { NULL, NULL }
2264 }; 2269 };
2265 2270
2266 const char* statement_data[] = { 2271 const char* statement_data[] = {
2267 "foo: 1, bar: 2", 2272 "foo: 1, bar: 2",
2268 "\"foo\": 1, \"bar\": 2", 2273 "\"foo\": 1, \"bar\": 2",
2269 "1: 1, 2: 2", 2274 "1: 1, 2: 2",
2270 // Syntax: IdentifierName ':' AssignmentExpression 2275 // Syntax: IdentifierName ':' AssignmentExpression
2271 "foo: bar = 5 + baz", 2276 "foo: bar = 5 + baz",
2272 // Syntax: 'get' (IdentifierName | String | Number) FunctionLiteral 2277 // Syntax: 'get' PropertyName '(' ')' '{' FunctionBody '}'
2273 "get foo() {}", 2278 "get foo() {}",
2274 "get \"foo\"() {}", 2279 "get \"foo\"() {}",
2275 "get 1() {}", 2280 "get 1() {}",
2276 // Syntax: 'set' (IdentifierName | String | Number) FunctionLiteral 2281 // Syntax: 'set' PropertyName '(' PropertySetParameterList ')'
2277 "set foo() {}", 2282 // '{' FunctionBody '}'
2278 "set \"foo\"() {}", 2283 "set foo(v) {}",
2279 "set 1() {}", 2284 "set \"foo\"(v) {}",
2285 "set 1(v) {}",
2280 // Non-colliding getters and setters -> no errors 2286 // Non-colliding getters and setters -> no errors
2281 "foo: 1, get bar() {}", 2287 "foo: 1, get bar() {}",
2282 "foo: 1, set bar(b) {}", 2288 "foo: 1, set bar(v) {}",
2283 "\"foo\": 1, get \"bar\"() {}", 2289 "\"foo\": 1, get \"bar\"() {}",
2284 "\"foo\": 1, set \"bar\"() {}", 2290 "\"foo\": 1, set \"bar\"(v) {}",
2285 "1: 1, get 2() {}", 2291 "1: 1, get 2() {}",
2286 "1: 1, set 2() {}", 2292 "1: 1, set 2(v) {}",
2287 // Weird number of parameters -> no errors
2288 "get bar() {}, set bar() {}",
2289 "get bar(x) {}, set bar(x) {}",
2290 "get bar(x, y) {}, set bar(x, y) {}",
2291 // Keywords, future reserved and strict future reserved are also allowed as 2293 // Keywords, future reserved and strict future reserved are also allowed as
2292 // property names. 2294 // property names.
2293 "if: 4", 2295 "if: 4",
2294 "interface: 5", 2296 "interface: 5",
2295 "super: 6", 2297 "super: 6",
2296 "eval: 7", 2298 "eval: 7",
2297 "arguments: 8", 2299 "arguments: 8",
2298 NULL 2300 NULL
2299 }; 2301 };
2300 2302
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 v8::Local<v8::String> source = 2542 v8::Local<v8::String> source =
2541 v8::String::NewFromTwoByte(isolate, two_byte_source); 2543 v8::String::NewFromTwoByte(isolate, two_byte_source);
2542 v8::Local<v8::Value> result = CompileRun(source); 2544 v8::Local<v8::Value> result = CompileRun(source);
2543 CHECK(result->IsString()); 2545 CHECK(result->IsString());
2544 v8::Local<v8::String> expected_name = 2546 v8::Local<v8::String> expected_name =
2545 v8::String::NewFromTwoByte(isolate, two_byte_name); 2547 v8::String::NewFromTwoByte(isolate, two_byte_name);
2546 CHECK(result->Equals(expected_name)); 2548 CHECK(result->Equals(expected_name));
2547 i::DeleteArray(two_byte_source); 2549 i::DeleteArray(two_byte_source);
2548 i::DeleteArray(two_byte_name); 2550 i::DeleteArray(two_byte_name);
2549 } 2551 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | test/mozilla/mozilla.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698