OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 | 221 |
222 v8::Local<Integer> DeclarationContext::Query(Local<Name> key) { | 222 v8::Local<Integer> DeclarationContext::Query(Local<Name> key) { |
223 return v8::Local<Integer>(); | 223 return v8::Local<Integer>(); |
224 } | 224 } |
225 | 225 |
226 | 226 |
227 // Test global declaration of a property the interceptor doesn't know | 227 // Test global declaration of a property the interceptor doesn't know |
228 // about and doesn't handle. | 228 // about and doesn't handle. |
229 TEST(Unknown) { | 229 TEST(Unknown) { |
230 i::FLAG_legacy_const = true; | |
231 HandleScope scope(CcTest::isolate()); | 230 HandleScope scope(CcTest::isolate()); |
232 v8::V8::Initialize(); | 231 v8::V8::Initialize(); |
233 | 232 |
234 { DeclarationContext context; | 233 { DeclarationContext context; |
235 context.Check("var x; x", | 234 context.Check("var x; x", |
236 1, // access | 235 1, // access |
237 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); | 236 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); |
238 } | 237 } |
239 | 238 |
240 { DeclarationContext context; | 239 { DeclarationContext context; |
241 context.Check("var x = 0; x", | 240 context.Check("var x = 0; x", |
242 1, // access | 241 1, // access |
243 1, // initialization | 242 1, // initialization |
244 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 243 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
245 } | 244 } |
246 | 245 |
247 { DeclarationContext context; | 246 { DeclarationContext context; |
248 context.Check("function x() { }; x", | 247 context.Check("function x() { }; x", |
249 1, // access | 248 1, // access |
250 0, | 249 0, |
251 0, | 250 0, |
252 EXPECT_RESULT); | 251 EXPECT_RESULT); |
253 } | 252 } |
254 | |
255 { DeclarationContext context; | |
256 context.Check("const x; x", | |
257 1, // access | |
258 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); | |
259 } | |
260 | |
261 { DeclarationContext context; | |
262 context.Check("const x = 0; x", | |
263 1, // access | |
264 0, | |
265 0, | |
266 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | |
267 } | |
268 } | 253 } |
269 | 254 |
270 | 255 |
271 class AbsentPropertyContext: public DeclarationContext { | 256 class AbsentPropertyContext: public DeclarationContext { |
272 protected: | 257 protected: |
273 virtual v8::Local<Integer> Query(Local<Name> key) { | 258 virtual v8::Local<Integer> Query(Local<Name> key) { |
274 return v8::Local<Integer>(); | 259 return v8::Local<Integer>(); |
275 } | 260 } |
276 }; | 261 }; |
277 | 262 |
278 | 263 |
279 TEST(Absent) { | 264 TEST(Absent) { |
280 i::FLAG_legacy_const = true; | |
281 v8::Isolate* isolate = CcTest::isolate(); | 265 v8::Isolate* isolate = CcTest::isolate(); |
282 v8::V8::Initialize(); | 266 v8::V8::Initialize(); |
283 HandleScope scope(isolate); | 267 HandleScope scope(isolate); |
284 | 268 |
285 { AbsentPropertyContext context; | 269 { AbsentPropertyContext context; |
286 context.Check("var x; x", | 270 context.Check("var x; x", |
287 1, // access | 271 1, // access |
288 0, 0, EXPECT_RESULT, Undefined(isolate)); | 272 0, 0, EXPECT_RESULT, Undefined(isolate)); |
289 } | 273 } |
290 | 274 |
291 { AbsentPropertyContext context; | 275 { AbsentPropertyContext context; |
292 context.Check("var x = 0; x", | 276 context.Check("var x = 0; x", |
293 1, // access | 277 1, // access |
294 1, // initialization | 278 1, // initialization |
295 0, EXPECT_RESULT, Number::New(isolate, 0)); | 279 0, EXPECT_RESULT, Number::New(isolate, 0)); |
296 } | 280 } |
297 | 281 |
298 { AbsentPropertyContext context; | 282 { AbsentPropertyContext context; |
299 context.Check("function x() { }; x", | 283 context.Check("function x() { }; x", |
300 1, // access | 284 1, // access |
301 0, | 285 0, |
302 0, | 286 0, |
303 EXPECT_RESULT); | 287 EXPECT_RESULT); |
304 } | 288 } |
305 | 289 |
306 { AbsentPropertyContext context; | 290 { AbsentPropertyContext context; |
307 context.Check("const x; x", | |
308 1, // access | |
309 0, 0, EXPECT_RESULT, Undefined(isolate)); | |
310 } | |
311 | |
312 { AbsentPropertyContext context; | |
313 context.Check("const x = 0; x", | |
314 1, // access | |
315 0, 0, EXPECT_RESULT, Number::New(isolate, 0)); | |
316 } | |
317 | |
318 { AbsentPropertyContext context; | |
319 context.Check("if (false) { var x = 0 }; x", | 291 context.Check("if (false) { var x = 0 }; x", |
320 1, // access | 292 1, // access |
321 0, 0, EXPECT_RESULT, Undefined(isolate)); | 293 0, 0, EXPECT_RESULT, Undefined(isolate)); |
322 } | 294 } |
323 } | 295 } |
324 | 296 |
325 | 297 |
326 | 298 |
327 class AppearingPropertyContext: public DeclarationContext { | 299 class AppearingPropertyContext: public DeclarationContext { |
328 public: | 300 public: |
(...skipping 25 matching lines...) Expand all Loading... |
354 // Do the lookup in the object. | 326 // Do the lookup in the object. |
355 return v8::Local<Integer>(); | 327 return v8::Local<Integer>(); |
356 } | 328 } |
357 | 329 |
358 private: | 330 private: |
359 State state_; | 331 State state_; |
360 }; | 332 }; |
361 | 333 |
362 | 334 |
363 TEST(Appearing) { | 335 TEST(Appearing) { |
364 i::FLAG_legacy_const = true; | |
365 v8::V8::Initialize(); | 336 v8::V8::Initialize(); |
366 HandleScope scope(CcTest::isolate()); | 337 HandleScope scope(CcTest::isolate()); |
367 | 338 |
368 { AppearingPropertyContext context; | 339 { AppearingPropertyContext context; |
369 context.Check("var x; x", | 340 context.Check("var x; x", |
370 1, // access | 341 1, // access |
371 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); | 342 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); |
372 } | 343 } |
373 | 344 |
374 { AppearingPropertyContext context; | 345 { AppearingPropertyContext context; |
375 context.Check("var x = 0; x", | 346 context.Check("var x = 0; x", |
376 1, // access | 347 1, // access |
377 1, // initialization | 348 1, // initialization |
378 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 349 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
379 } | 350 } |
380 | 351 |
381 { AppearingPropertyContext context; | 352 { AppearingPropertyContext context; |
382 context.Check("function x() { }; x", | 353 context.Check("function x() { }; x", |
383 1, // access | 354 1, // access |
384 0, | 355 0, |
385 0, | 356 0, |
386 EXPECT_RESULT); | 357 EXPECT_RESULT); |
387 } | 358 } |
388 | |
389 { AppearingPropertyContext context; | |
390 context.Check("const x; x", | |
391 1, // access | |
392 0, 0, EXPECT_RESULT, Undefined(CcTest::isolate())); | |
393 } | |
394 | |
395 { AppearingPropertyContext context; | |
396 context.Check("const x = 0; x", | |
397 1, // access | |
398 0, 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | |
399 } | |
400 } | 359 } |
401 | 360 |
402 | 361 |
403 | 362 |
404 class ExistsInPrototypeContext: public DeclarationContext { | 363 class ExistsInPrototypeContext: public DeclarationContext { |
405 public: | 364 public: |
406 ExistsInPrototypeContext() { InitializeIfNeeded(); } | 365 ExistsInPrototypeContext() { InitializeIfNeeded(); } |
407 protected: | 366 protected: |
408 virtual v8::Local<Integer> Query(Local<Name> key) { | 367 virtual v8::Local<Integer> Query(Local<Name> key) { |
409 // Let it seem that the property exists in the prototype object. | 368 // Let it seem that the property exists in the prototype object. |
410 return Integer::New(isolate(), v8::None); | 369 return Integer::New(isolate(), v8::None); |
411 } | 370 } |
412 | 371 |
413 // Use the prototype as the holder for the interceptors. | 372 // Use the prototype as the holder for the interceptors. |
414 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 373 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
415 return function->PrototypeTemplate(); | 374 return function->PrototypeTemplate(); |
416 } | 375 } |
417 }; | 376 }; |
418 | 377 |
419 | 378 |
420 TEST(ExistsInPrototype) { | 379 TEST(ExistsInPrototype) { |
421 i::FLAG_legacy_const = true; | |
422 HandleScope scope(CcTest::isolate()); | 380 HandleScope scope(CcTest::isolate()); |
423 | 381 |
424 // Sanity check to make sure that the holder of the interceptor | 382 // Sanity check to make sure that the holder of the interceptor |
425 // really is the prototype object. | 383 // really is the prototype object. |
426 { ExistsInPrototypeContext context; | 384 { ExistsInPrototypeContext context; |
427 context.Check("this.x = 87; this.x", 0, 0, 1, EXPECT_RESULT, | 385 context.Check("this.x = 87; this.x", 0, 0, 1, EXPECT_RESULT, |
428 Number::New(CcTest::isolate(), 87)); | 386 Number::New(CcTest::isolate(), 87)); |
429 } | 387 } |
430 | 388 |
431 { ExistsInPrototypeContext context; | 389 { ExistsInPrototypeContext context; |
432 context.Check("var x; x", | 390 context.Check("var x; x", |
433 0, | 391 0, |
434 0, | 392 0, |
435 0, | 393 0, |
436 EXPECT_RESULT, Undefined(CcTest::isolate())); | 394 EXPECT_RESULT, Undefined(CcTest::isolate())); |
437 } | 395 } |
438 | 396 |
439 { ExistsInPrototypeContext context; | 397 { ExistsInPrototypeContext context; |
440 context.Check("var x = 0; x", | 398 context.Check("var x = 0; x", |
441 0, | 399 0, |
442 0, | 400 0, |
443 0, | 401 0, |
444 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 402 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
445 } | 403 } |
446 | |
447 { ExistsInPrototypeContext context; | |
448 context.Check("const x; x", | |
449 0, | |
450 0, | |
451 0, | |
452 EXPECT_RESULT, Undefined(CcTest::isolate())); | |
453 } | |
454 | |
455 { ExistsInPrototypeContext context; | |
456 context.Check("const x = 0; x", | |
457 0, | |
458 0, | |
459 0, | |
460 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | |
461 } | |
462 } | 404 } |
463 | 405 |
464 | 406 |
465 | 407 |
466 class AbsentInPrototypeContext: public DeclarationContext { | 408 class AbsentInPrototypeContext: public DeclarationContext { |
467 protected: | 409 protected: |
468 virtual v8::Local<Integer> Query(Local<Name> key) { | 410 virtual v8::Local<Integer> Query(Local<Name> key) { |
469 // Let it seem that the property is absent in the prototype object. | 411 // Let it seem that the property is absent in the prototype object. |
470 return Local<Integer>(); | 412 return Local<Integer>(); |
471 } | 413 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 463 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
522 return hidden_proto_->InstanceTemplate(); | 464 return hidden_proto_->InstanceTemplate(); |
523 } | 465 } |
524 | 466 |
525 private: | 467 private: |
526 Local<FunctionTemplate> hidden_proto_; | 468 Local<FunctionTemplate> hidden_proto_; |
527 }; | 469 }; |
528 | 470 |
529 | 471 |
530 TEST(ExistsInHiddenPrototype) { | 472 TEST(ExistsInHiddenPrototype) { |
531 i::FLAG_legacy_const = true; | |
532 HandleScope scope(CcTest::isolate()); | 473 HandleScope scope(CcTest::isolate()); |
533 | 474 |
534 { ExistsInHiddenPrototypeContext context; | 475 { ExistsInHiddenPrototypeContext context; |
535 context.Check("var x; x", 0, 0, 0, EXPECT_RESULT, | 476 context.Check("var x; x", 0, 0, 0, EXPECT_RESULT, |
536 Undefined(CcTest::isolate())); | 477 Undefined(CcTest::isolate())); |
537 } | 478 } |
538 | 479 |
539 { ExistsInHiddenPrototypeContext context; | 480 { ExistsInHiddenPrototypeContext context; |
540 context.Check("var x = 0; x", 0, 0, 0, EXPECT_RESULT, | 481 context.Check("var x = 0; x", 0, 0, 0, EXPECT_RESULT, |
541 Number::New(CcTest::isolate(), 0)); | 482 Number::New(CcTest::isolate(), 0)); |
542 } | 483 } |
543 | 484 |
544 { ExistsInHiddenPrototypeContext context; | 485 { ExistsInHiddenPrototypeContext context; |
545 context.Check("function x() { }; x", | 486 context.Check("function x() { }; x", |
546 0, | 487 0, |
547 0, | 488 0, |
548 0, | 489 0, |
549 EXPECT_RESULT); | 490 EXPECT_RESULT); |
550 } | 491 } |
551 | |
552 // TODO(mstarzinger): The semantics of global const is vague. | |
553 { ExistsInHiddenPrototypeContext context; | |
554 context.Check("const x; x", 0, 0, 0, EXPECT_RESULT, | |
555 Undefined(CcTest::isolate())); | |
556 } | |
557 | |
558 // TODO(mstarzinger): The semantics of global const is vague. | |
559 { ExistsInHiddenPrototypeContext context; | |
560 context.Check("const x = 0; x", 0, 0, 0, EXPECT_RESULT, | |
561 Number::New(CcTest::isolate(), 0)); | |
562 } | |
563 } | 492 } |
564 | 493 |
565 | 494 |
566 | 495 |
567 class SimpleContext { | 496 class SimpleContext { |
568 public: | 497 public: |
569 SimpleContext() | 498 SimpleContext() |
570 : handle_scope_(CcTest::isolate()), | 499 : handle_scope_(CcTest::isolate()), |
571 context_(Context::New(CcTest::isolate())) { | 500 context_(Context::New(CcTest::isolate())) { |
572 context_->Enter(); | 501 context_->Enter(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 534 } |
606 } | 535 } |
607 | 536 |
608 private: | 537 private: |
609 HandleScope handle_scope_; | 538 HandleScope handle_scope_; |
610 Local<Context> context_; | 539 Local<Context> context_; |
611 }; | 540 }; |
612 | 541 |
613 | 542 |
614 TEST(CrossScriptReferences) { | 543 TEST(CrossScriptReferences) { |
615 i::FLAG_legacy_const = true; | |
616 v8::Isolate* isolate = CcTest::isolate(); | 544 v8::Isolate* isolate = CcTest::isolate(); |
617 HandleScope scope(isolate); | 545 HandleScope scope(isolate); |
618 | 546 |
619 { SimpleContext context; | 547 { SimpleContext context; |
620 context.Check("var x = 1; x", | 548 context.Check("var x = 1; x", |
621 EXPECT_RESULT, Number::New(isolate, 1)); | 549 EXPECT_RESULT, Number::New(isolate, 1)); |
622 context.Check("var x = 2; x", | 550 context.Check("var x = 2; x", |
623 EXPECT_RESULT, Number::New(isolate, 2)); | 551 EXPECT_RESULT, Number::New(isolate, 2)); |
624 context.Check("const x = 3; x", EXPECT_EXCEPTION); | |
625 context.Check("const x = 4; x", EXPECT_EXCEPTION); | |
626 context.Check("x = 5; x", | 552 context.Check("x = 5; x", |
627 EXPECT_RESULT, Number::New(isolate, 5)); | 553 EXPECT_RESULT, Number::New(isolate, 5)); |
628 context.Check("var x = 6; x", | 554 context.Check("var x = 6; x", |
629 EXPECT_RESULT, Number::New(isolate, 6)); | 555 EXPECT_RESULT, Number::New(isolate, 6)); |
630 context.Check("this.x", | 556 context.Check("this.x", |
631 EXPECT_RESULT, Number::New(isolate, 6)); | 557 EXPECT_RESULT, Number::New(isolate, 6)); |
632 context.Check("function x() { return 7 }; x()", | 558 context.Check("function x() { return 7 }; x()", |
633 EXPECT_RESULT, Number::New(isolate, 7)); | 559 EXPECT_RESULT, Number::New(isolate, 7)); |
634 } | 560 } |
635 | |
636 { SimpleContext context; | |
637 context.Check("const x = 1; x", | |
638 EXPECT_RESULT, Number::New(isolate, 1)); | |
639 context.Check("var x = 2; x", // assignment ignored | |
640 EXPECT_RESULT, Number::New(isolate, 1)); | |
641 context.Check("const x = 3; x", EXPECT_EXCEPTION); | |
642 context.Check("x = 4; x", // assignment ignored | |
643 EXPECT_RESULT, Number::New(isolate, 1)); | |
644 context.Check("var x = 5; x", // assignment ignored | |
645 EXPECT_RESULT, Number::New(isolate, 1)); | |
646 context.Check("this.x", | |
647 EXPECT_RESULT, Number::New(isolate, 1)); | |
648 context.Check("function x() { return 7 }; x", | |
649 EXPECT_EXCEPTION); | |
650 } | |
651 } | 561 } |
652 | 562 |
653 | 563 |
654 TEST(CrossScriptReferences_Simple) { | 564 TEST(CrossScriptReferences_Simple) { |
655 i::FLAG_use_strict = true; | 565 i::FLAG_use_strict = true; |
656 | 566 |
657 v8::Isolate* isolate = CcTest::isolate(); | 567 v8::Isolate* isolate = CcTest::isolate(); |
658 HandleScope scope(isolate); | 568 HandleScope scope(isolate); |
659 | 569 |
660 { | 570 { |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 Undefined(CcTest::isolate())); | 1174 Undefined(CcTest::isolate())); |
1265 for (int i = 0; i < 4; i++) { | 1175 for (int i = 0; i < 4; i++) { |
1266 context.Check("f()", EXPECT_EXCEPTION); | 1176 context.Check("f()", EXPECT_EXCEPTION); |
1267 } | 1177 } |
1268 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, | 1178 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, |
1269 Undefined(CcTest::isolate())); | 1179 Undefined(CcTest::isolate())); |
1270 | 1180 |
1271 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); | 1181 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); |
1272 } | 1182 } |
1273 } | 1183 } |
OLD | NEW |