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

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: Fix arm 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
« no previous file with comments | « src/messages.js ('k') | src/x64/builtins-x64.cc » ('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 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 411 }
412 412
413 413
414 function APPLY_PREPARE(args) { 414 function APPLY_PREPARE(args) {
415 var length; 415 var length;
416 // First check whether length is a positive Smi and args is an 416 // First check whether length is a positive Smi and args is an
417 // array. This is the fast case. If this fails, we do the slow case 417 // array. This is the fast case. If this fails, we do the slow case
418 // that takes care of more eventualities. 418 // that takes care of more eventualities.
419 if (IS_ARRAY(args)) { 419 if (IS_ARRAY(args)) {
420 length = args.length; 420 length = args.length;
421 if (%_IsSmi(length) && length >= 0 && length < 0x800000 && 421 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
422 IS_SPEC_FUNCTION(this)) { 422 IS_SPEC_FUNCTION(this)) {
423 return length; 423 return length;
424 } 424 }
425 } 425 }
426 426
427 length = (args == null) ? 0 : %ToUint32(args.length); 427 length = (args == null) ? 0 : %ToUint32(args.length);
428 428
429 // We can handle any number of apply arguments if the stack is 429 // We can handle any number of apply arguments if the stack is
430 // big enough, but sanity check the value to avoid overflow when 430 // big enough, but sanity check the value to avoid overflow when
431 // multiplying with pointer size. 431 // multiplying with pointer size.
432 if (length > 0x800000) { 432 if (length > kSafeArgumentsLength) {
433 throw %MakeRangeError('stack_overflow', []); 433 throw %MakeRangeError('stack_overflow', []);
434 } 434 }
435 435
436 if (!IS_SPEC_FUNCTION(this)) { 436 if (!IS_SPEC_FUNCTION(this)) {
437 throw %MakeTypeError('apply_non_function', 437 throw %MakeTypeError('apply_non_function',
438 [ %ToString(this), typeof this ]); 438 [ %ToString(this), typeof this ]);
439 } 439 }
440 440
441 // Make sure the arguments list has the right type. 441 // Make sure the arguments list has the right type.
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 < kSafeArgumentsLength &&
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 > kSafeArgumentsLength) {
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 < kSafeArgumentsLength &&
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 > kSafeArgumentsLength) {
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 785
699 /* ----------------------------------------------- 786 /* -----------------------------------------------
700 - - - J a v a S c r i p t S t u b s - - - 787 - - - J a v a S c r i p t S t u b s - - -
701 ----------------------------------------------- 788 -----------------------------------------------
702 */ 789 */
703 790
704 function STRING_LENGTH_STUB(name) { 791 function STRING_LENGTH_STUB(name) {
705 var receiver = this; // implicit first parameter 792 var receiver = this; // implicit first parameter
706 return %_StringGetLength(%_JSValueGetValue(receiver)); 793 return %_StringGetLength(%_JSValueGetValue(receiver));
707 } 794 }
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698