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

Side by Side Diff: src/runtime.js

Issue 913073003: [es6] implement Reflect.apply() & Reflect.construct() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add Reflect.construct support Created 5 years, 9 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'. 9 // ALL CAPS. The compiled code passes the first argument in 'this'.
10 10
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 if (args != null && !IS_SPEC_OBJECT(args)) { 442 if (args != null && !IS_SPEC_OBJECT(args)) {
443 throw %MakeTypeError('apply_wrong_args', []); 443 throw %MakeTypeError('apply_wrong_args', []);
444 } 444 }
445 445
446 // Return the length which is the number of arguments to copy to the 446 // Return the length which is the number of arguments to copy to the
447 // stack. It is guaranteed to be a small integer at this point. 447 // stack. It is guaranteed to be a small integer at this point.
448 return length; 448 return length;
449 } 449 }
450 450
451 451
452 function REFLECT_APPLY_PREPARE(args) {
453 var length;
454 // First check whether length is a positive Smi and args is an
455 // array. This is the fast case. If this fails, we do the slow case
456 // that takes care of more eventualities.
457 if (IS_ARRAY(args)) {
458 length = args.length;
459 if (%_IsSmi(length) && length >= 0 && length < 0x800000 &&
460 IS_SPEC_FUNCTION(this)) {
461 return length;
462 }
463 }
464
465 if (!IS_SPEC_FUNCTION(this)) {
466 throw %MakeTypeError('called_non_callable', [ %ToString(this) ]);
467 }
468
469 if (!IS_SPEC_OBJECT(args)) {
470 throw %MakeTypeError('reflect_apply_wrong_args', [ ]);
471 }
472
473 length = %ToLength(args.length);
474
475 // We can handle any number of apply arguments if the stack is
476 // big enough, but sanity check the value to avoid overflow when
477 // multiplying with pointer size.
478 if (length > 0x800000) {
arv (Not doing code reviews) 2015/03/03 14:25:52 maybe add a const/macro for this?
caitp (gmail) 2015/03/03 15:53:49 Replaced the magic number with a macro, hows that?
479 throw %MakeRangeError('stack_overflow', []);
480 }
481
482 // Return the length which is the number of arguments to copy to the
483 // stack. It is guaranteed to be a small integer at this point.
484 return length;
485 }
486
487
488 function REFLECT_CONSTRUCT_PREPARE(args, newTarget) {
489 var length;
490 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this);
491 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget);
492
493 // First check whether length is a positive Smi and args is an
494 // array. This is the fast case. If this fails, we do the slow case
495 // that takes care of more eventualities.
496 if (IS_ARRAY(args)) {
497 length = args.length;
498 if (%_IsSmi(length) && length >= 0 && length < 0x800000 &&
499 ctorOk && newTargetOk) {
500 return length;
501 }
502 }
503
504 if (!ctorOk) {
505 if (!IS_SPEC_FUNCTION(this)) {
506 throw %MakeTypeError('called_non_callable', [ %ToString(this) ]);
507 } else {
508 throw %MakeTypeError('not_constructor', [ %ToString(this) ]);
509 }
510 }
511
512 if (!newTargetOk) {
513 if (!IS_SPEC_FUNCTION(newTarget)) {
514 throw %MakeTypeError('called_non_callable', [ %ToString(newTarget) ]);
515 } else {
516 throw %MakeTypeError('not_constructor', [ %ToString(newTarget) ]);
517 }
518 }
519
520 if (!IS_SPEC_OBJECT(args)) {
521 throw %MakeTypeError('reflect_construct_wrong_args', [ ]);
522 }
523
524 length = %ToLength(args.length);
525
526 // We can handle any number of apply arguments if the stack is
527 // big enough, but sanity check the value to avoid overflow when
528 // multiplying with pointer size.
529 if (length > 0x800000) {
530 throw %MakeRangeError('stack_overflow', []);
531 }
532
533 // Return the length which is the number of arguments to copy to the
534 // stack. It is guaranteed to be a small integer at this point.
535 return length;
536 }
537
538
452 function STACK_OVERFLOW(length) { 539 function STACK_OVERFLOW(length) {
453 throw %MakeRangeError('stack_overflow', []); 540 throw %MakeRangeError('stack_overflow', []);
454 } 541 }
455 542
456 543
457 // Convert the receiver to an object - forward to ToObject. 544 // Convert the receiver to an object - forward to ToObject.
458 function TO_OBJECT() { 545 function TO_OBJECT() {
459 return %ToObject(this); 546 return %ToObject(this);
460 } 547 }
461 548
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return i; 774 return i;
688 } 775 }
689 776
690 777
691 // NOTE: Setting the prototype for Array must take place as early as 778 // NOTE: Setting the prototype for Array must take place as early as
692 // possible due to code generation for array literals. When 779 // possible due to code generation for array literals. When
693 // generating code for a array literal a boilerplate array is created 780 // generating code for a array literal a boilerplate array is created
694 // that is cloned when running the code. It is essential that the 781 // that is cloned when running the code. It is essential that the
695 // boilerplate gets the right prototype. 782 // boilerplate gets the right prototype.
696 %FunctionSetPrototype($Array, new $Array(0)); 783 %FunctionSetPrototype($Array, new $Array(0));
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/x64/builtins-x64.cc » ('j') | test/mjsunit/harmony/reflect-apply.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698