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

Side by Side Diff: src/builtins.cc

Issue 1148007: Merge bleeding_edge from version 2.1.3 up to revision 4205... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « src/builtins.h ('k') | src/cached-powers.h » ('j') | src/heap.cc » ('J')
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 // 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 ASSERT(proto->elements() == Heap::empty_fixed_array()); 312 ASSERT(proto->elements() == Heap::empty_fixed_array());
313 // Object.prototype 313 // Object.prototype
314 proto = JSObject::cast(proto->GetPrototype()); 314 proto = JSObject::cast(proto->GetPrototype());
315 if (proto != global_context->initial_object_prototype()) return false; 315 if (proto != global_context->initial_object_prototype()) return false;
316 if (proto->elements() != Heap::empty_fixed_array()) return false; 316 if (proto->elements() != Heap::empty_fixed_array()) return false;
317 ASSERT(proto->GetPrototype()->IsNull()); 317 ASSERT(proto->GetPrototype()->IsNull());
318 return true; 318 return true;
319 } 319 }
320 320
321 321
322 static bool IsJSArrayWithFastElements(Object* receiver,
323 FixedArray** elements) {
324 if (!receiver->IsJSArray()) {
325 return false;
326 }
327
328 JSArray* array = JSArray::cast(receiver);
329
330 HeapObject* elms = HeapObject::cast(array->elements());
331 if (elms->map() != Heap::fixed_array_map()) {
332 return false;
333 }
334
335 *elements = FixedArray::cast(elms);
336 return true;
337 }
338
339
322 static Object* CallJsBuiltin(const char* name, 340 static Object* CallJsBuiltin(const char* name,
323 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { 341 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
324 HandleScope handleScope; 342 HandleScope handleScope;
325 343
326 Handle<Object> js_builtin = 344 Handle<Object> js_builtin =
327 GetProperty(Handle<JSObject>(Top::global_context()->builtins()), 345 GetProperty(Handle<JSObject>(Top::global_context()->builtins()),
328 name); 346 name);
329 ASSERT(js_builtin->IsJSFunction()); 347 ASSERT(js_builtin->IsJSFunction());
330 Handle<JSFunction> function(Handle<JSFunction>::cast(js_builtin)); 348 Handle<JSFunction> function(Handle<JSFunction>::cast(js_builtin));
331 Vector<Object**> argv(Vector<Object**>::New(args.length() - 1)); 349 Vector<Object**> argv(Vector<Object**>::New(args.length() - 1));
332 int n_args = args.length() - 1; 350 int n_args = args.length() - 1;
333 for (int i = 0; i < n_args; i++) { 351 for (int i = 0; i < n_args; i++) {
334 argv[i] = &args[i + 1]; 352 argv[i] = args.at<Object>(i + 1).location();
335 } 353 }
336 bool pending_exception = false; 354 bool pending_exception = false;
337 Handle<Object> result = Execution::Call(function, 355 Handle<Object> result = Execution::Call(function,
338 args.receiver(), 356 args.receiver(),
339 n_args, 357 n_args,
340 argv.start(), 358 argv.start(),
341 &pending_exception); 359 &pending_exception);
342 argv.Dispose(); 360 argv.Dispose();
343 if (pending_exception) return Failure::Exception(); 361 if (pending_exception) return Failure::Exception();
344 return *result; 362 return *result;
345 } 363 }
346 364
347 365
348 BUILTIN(ArrayPush) { 366 BUILTIN(ArrayPush) {
349 JSArray* array = JSArray::cast(*args.receiver()); 367 Object* receiver = *args.receiver();
350 ASSERT(array->HasFastElements()); 368 FixedArray* elms = NULL;
369 if (!IsJSArrayWithFastElements(receiver, &elms)) {
370 return CallJsBuiltin("ArrayPush", args);
371 }
372 JSArray* array = JSArray::cast(receiver);
351 373
352 int len = Smi::cast(array->length())->value(); 374 int len = Smi::cast(array->length())->value();
353 int to_add = args.length() - 1; 375 int to_add = args.length() - 1;
354 if (to_add == 0) { 376 if (to_add == 0) {
355 return Smi::FromInt(len); 377 return Smi::FromInt(len);
356 } 378 }
357 // Currently fixed arrays cannot grow too big, so 379 // Currently fixed arrays cannot grow too big, so
358 // we should never hit this case. 380 // we should never hit this case.
359 ASSERT(to_add <= (Smi::kMaxValue - len)); 381 ASSERT(to_add <= (Smi::kMaxValue - len));
360 382
361 int new_length = len + to_add; 383 int new_length = len + to_add;
362 FixedArray* elms = FixedArray::cast(array->elements());
363 384
364 if (new_length > elms->length()) { 385 if (new_length > elms->length()) {
365 // New backing storage is needed. 386 // New backing storage is needed.
366 int capacity = new_length + (new_length >> 1) + 16; 387 int capacity = new_length + (new_length >> 1) + 16;
367 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); 388 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
368 if (obj->IsFailure()) return obj; 389 if (obj->IsFailure()) return obj;
369 FixedArray* new_elms = FixedArray::cast(obj); 390 FixedArray* new_elms = FixedArray::cast(obj);
370 391
371 AssertNoAllocation no_gc; 392 AssertNoAllocation no_gc;
372 CopyElements(&no_gc, new_elms, 0, elms, 0, len); 393 CopyElements(&no_gc, new_elms, 0, elms, 0, len);
(...skipping 10 matching lines...) Expand all
383 elms->set(index + len, args[index + 1], mode); 404 elms->set(index + len, args[index + 1], mode);
384 } 405 }
385 406
386 // Set the length. 407 // Set the length.
387 array->set_length(Smi::FromInt(new_length)); 408 array->set_length(Smi::FromInt(new_length));
388 return Smi::FromInt(new_length); 409 return Smi::FromInt(new_length);
389 } 410 }
390 411
391 412
392 BUILTIN(ArrayPop) { 413 BUILTIN(ArrayPop) {
393 JSArray* array = JSArray::cast(*args.receiver()); 414 Object* receiver = *args.receiver();
394 ASSERT(array->HasFastElements()); 415 FixedArray* elms = NULL;
416 if (!IsJSArrayWithFastElements(receiver, &elms)) {
417 return CallJsBuiltin("ArrayPop", args);
418 }
419 JSArray* array = JSArray::cast(receiver);
395 420
396 int len = Smi::cast(array->length())->value(); 421 int len = Smi::cast(array->length())->value();
397 if (len == 0) return Heap::undefined_value(); 422 if (len == 0) return Heap::undefined_value();
398 423
399 // Get top element 424 // Get top element
400 FixedArray* elms = FixedArray::cast(array->elements());
401 Object* top = elms->get(len - 1); 425 Object* top = elms->get(len - 1);
402 426
403 // Set the length. 427 // Set the length.
404 array->set_length(Smi::FromInt(len - 1)); 428 array->set_length(Smi::FromInt(len - 1));
405 429
406 if (!top->IsTheHole()) { 430 if (!top->IsTheHole()) {
407 // Delete the top element. 431 // Delete the top element.
408 elms->set_the_hole(len - 1); 432 elms->set_the_hole(len - 1);
409 return top; 433 return top;
410 } 434 }
411 435
412 // Remember to check the prototype chain. 436 // Remember to check the prototype chain.
413 JSFunction* array_function = 437 JSFunction* array_function =
414 Top::context()->global_context()->array_function(); 438 Top::context()->global_context()->array_function();
415 JSObject* prototype = JSObject::cast(array_function->prototype()); 439 JSObject* prototype = JSObject::cast(array_function->prototype());
416 top = prototype->GetElement(len - 1); 440 top = prototype->GetElement(len - 1);
417 441
418 return top; 442 return top;
419 } 443 }
420 444
421 445
422 BUILTIN(ArrayShift) { 446 BUILTIN(ArrayShift) {
423 if (!ArrayPrototypeHasNoElements()) { 447 Object* receiver = *args.receiver();
448 FixedArray* elms = NULL;
449 if (!IsJSArrayWithFastElements(receiver, &elms)
450 || !ArrayPrototypeHasNoElements()) {
424 return CallJsBuiltin("ArrayShift", args); 451 return CallJsBuiltin("ArrayShift", args);
425 } 452 }
426 453 JSArray* array = JSArray::cast(receiver);
427 JSArray* array = JSArray::cast(*args.receiver());
428 ASSERT(array->HasFastElements()); 454 ASSERT(array->HasFastElements());
429 455
430 int len = Smi::cast(array->length())->value(); 456 int len = Smi::cast(array->length())->value();
431 if (len == 0) return Heap::undefined_value(); 457 if (len == 0) return Heap::undefined_value();
432 458
433 FixedArray* elms = FixedArray::cast(array->elements());
434
435 // Get first element 459 // Get first element
436 Object* first = elms->get(0); 460 Object* first = elms->get(0);
437 if (first->IsTheHole()) { 461 if (first->IsTheHole()) {
438 first = Heap::undefined_value(); 462 first = Heap::undefined_value();
439 } 463 }
440 464
441 // Shift the elements. 465 // Shift the elements.
442 AssertNoAllocation no_gc; 466 AssertNoAllocation no_gc;
443 MoveElements(&no_gc, elms, 0, elms, 1, len - 1); 467 MoveElements(&no_gc, elms, 0, elms, 1, len - 1);
444 elms->set(len - 1, Heap::the_hole_value()); 468 elms->set(len - 1, Heap::the_hole_value());
445 469
446 // Set the length. 470 // Set the length.
447 array->set_length(Smi::FromInt(len - 1)); 471 array->set_length(Smi::FromInt(len - 1));
448 472
449 return first; 473 return first;
450 } 474 }
451 475
452 476
453 BUILTIN(ArrayUnshift) { 477 BUILTIN(ArrayUnshift) {
454 if (!ArrayPrototypeHasNoElements()) { 478 Object* receiver = *args.receiver();
479 FixedArray* elms = NULL;
480 if (!IsJSArrayWithFastElements(receiver, &elms)
481 || !ArrayPrototypeHasNoElements()) {
455 return CallJsBuiltin("ArrayUnshift", args); 482 return CallJsBuiltin("ArrayUnshift", args);
456 } 483 }
457 484 JSArray* array = JSArray::cast(receiver);
458 JSArray* array = JSArray::cast(*args.receiver());
459 ASSERT(array->HasFastElements()); 485 ASSERT(array->HasFastElements());
460 486
461 int len = Smi::cast(array->length())->value(); 487 int len = Smi::cast(array->length())->value();
462 int to_add = args.length() - 1; 488 int to_add = args.length() - 1;
463 // Note that we cannot quit early if to_add == 0 as
464 // values should be lifted from prototype into
465 // the array.
466
467 int new_length = len + to_add; 489 int new_length = len + to_add;
468 // Currently fixed arrays cannot grow too big, so 490 // Currently fixed arrays cannot grow too big, so
469 // we should never hit this case. 491 // we should never hit this case.
470 ASSERT(to_add <= (Smi::kMaxValue - len)); 492 ASSERT(to_add <= (Smi::kMaxValue - len));
471 493
472 FixedArray* elms = FixedArray::cast(array->elements());
473
474 if (new_length > elms->length()) { 494 if (new_length > elms->length()) {
475 // New backing storage is needed. 495 // New backing storage is needed.
476 int capacity = new_length + (new_length >> 1) + 16; 496 int capacity = new_length + (new_length >> 1) + 16;
477 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); 497 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
478 if (obj->IsFailure()) return obj; 498 if (obj->IsFailure()) return obj;
479 FixedArray* new_elms = FixedArray::cast(obj); 499 FixedArray* new_elms = FixedArray::cast(obj);
480 500
481 AssertNoAllocation no_gc; 501 AssertNoAllocation no_gc;
482 CopyElements(&no_gc, new_elms, to_add, elms, 0, len); 502 CopyElements(&no_gc, new_elms, to_add, elms, 0, len);
483 FillWithHoles(new_elms, new_length, capacity); 503 FillWithHoles(new_elms, new_length, capacity);
(...skipping 12 matching lines...) Expand all
496 elms->set(i, args[i + 1], mode); 516 elms->set(i, args[i + 1], mode);
497 } 517 }
498 518
499 // Set the length. 519 // Set the length.
500 array->set_length(Smi::FromInt(new_length)); 520 array->set_length(Smi::FromInt(new_length));
501 return Smi::FromInt(new_length); 521 return Smi::FromInt(new_length);
502 } 522 }
503 523
504 524
505 BUILTIN(ArraySlice) { 525 BUILTIN(ArraySlice) {
506 if (!ArrayPrototypeHasNoElements()) { 526 Object* receiver = *args.receiver();
527 FixedArray* elms = NULL;
528 if (!IsJSArrayWithFastElements(receiver, &elms)
529 || !ArrayPrototypeHasNoElements()) {
507 return CallJsBuiltin("ArraySlice", args); 530 return CallJsBuiltin("ArraySlice", args);
508 } 531 }
509 532 JSArray* array = JSArray::cast(receiver);
510 JSArray* array = JSArray::cast(*args.receiver());
511 ASSERT(array->HasFastElements()); 533 ASSERT(array->HasFastElements());
512 534
513 int len = Smi::cast(array->length())->value(); 535 int len = Smi::cast(array->length())->value();
514 536
515 int n_arguments = args.length() - 1; 537 int n_arguments = args.length() - 1;
516 538
517 // Note carefully choosen defaults---if argument is missing, 539 // Note carefully choosen defaults---if argument is missing,
518 // it's undefined which gets converted to 0 for relative_start 540 // it's undefined which gets converted to 0 for relative_start
519 // and to len for relative_end. 541 // and to len for relative_end.
520 int relative_start = 0; 542 int relative_start = 0;
(...skipping 30 matching lines...) Expand all
551 } 573 }
552 574
553 Object* result = AllocateJSArray(); 575 Object* result = AllocateJSArray();
554 if (result->IsFailure()) return result; 576 if (result->IsFailure()) return result;
555 JSArray* result_array = JSArray::cast(result); 577 JSArray* result_array = JSArray::cast(result);
556 578
557 result = Heap::AllocateUninitializedFixedArray(result_len); 579 result = Heap::AllocateUninitializedFixedArray(result_len);
558 if (result->IsFailure()) return result; 580 if (result->IsFailure()) return result;
559 FixedArray* result_elms = FixedArray::cast(result); 581 FixedArray* result_elms = FixedArray::cast(result);
560 582
561 FixedArray* elms = FixedArray::cast(array->elements());
562
563 AssertNoAllocation no_gc; 583 AssertNoAllocation no_gc;
564 CopyElements(&no_gc, result_elms, 0, elms, k, result_len); 584 CopyElements(&no_gc, result_elms, 0, elms, k, result_len);
565 585
566 // Set elements. 586 // Set elements.
567 result_array->set_elements(result_elms); 587 result_array->set_elements(result_elms);
568 588
569 // Set the length. 589 // Set the length.
570 result_array->set_length(Smi::FromInt(result_len)); 590 result_array->set_length(Smi::FromInt(result_len));
571 return result_array; 591 return result_array;
572 } 592 }
573 593
574 594
575 BUILTIN(ArraySplice) { 595 BUILTIN(ArraySplice) {
576 if (!ArrayPrototypeHasNoElements()) { 596 Object* receiver = *args.receiver();
597 FixedArray* elms = NULL;
598 if (!IsJSArrayWithFastElements(receiver, &elms)
599 || !ArrayPrototypeHasNoElements()) {
577 return CallJsBuiltin("ArraySplice", args); 600 return CallJsBuiltin("ArraySplice", args);
578 } 601 }
579 602 JSArray* array = JSArray::cast(receiver);
580 JSArray* array = JSArray::cast(*args.receiver());
581 ASSERT(array->HasFastElements()); 603 ASSERT(array->HasFastElements());
582 604
583 int len = Smi::cast(array->length())->value(); 605 int len = Smi::cast(array->length())->value();
584 606
585 int n_arguments = args.length() - 1; 607 int n_arguments = args.length() - 1;
586 608
587 // SpiderMonkey and JSC return undefined in the case where no 609 // SpiderMonkey and JSC return undefined in the case where no
588 // arguments are given instead of using the implicit undefined 610 // arguments are given instead of using the implicit undefined
589 // arguments. This does not follow ECMA-262, but we do the same for 611 // arguments. This does not follow ECMA-262, but we do the same for
590 // compatibility. 612 // compatibility.
(...skipping 20 matching lines...) Expand all
611 if (n_arguments > 1) { 633 if (n_arguments > 1) {
612 Object* arg2 = args[2]; 634 Object* arg2 = args[2];
613 if (arg2->IsSmi()) { 635 if (arg2->IsSmi()) {
614 delete_count = Smi::cast(arg2)->value(); 636 delete_count = Smi::cast(arg2)->value();
615 } else { 637 } else {
616 return CallJsBuiltin("ArraySplice", args); 638 return CallJsBuiltin("ArraySplice", args);
617 } 639 }
618 } 640 }
619 int actual_delete_count = Min(Max(delete_count, 0), len - actual_start); 641 int actual_delete_count = Min(Max(delete_count, 0), len - actual_start);
620 642
621 FixedArray* elms = FixedArray::cast(array->elements());
622
623 JSArray* result_array = NULL; 643 JSArray* result_array = NULL;
624 if (actual_delete_count == 0) { 644 if (actual_delete_count == 0) {
625 Object* result = AllocateEmptyJSArray(); 645 Object* result = AllocateEmptyJSArray();
626 if (result->IsFailure()) return result; 646 if (result->IsFailure()) return result;
627 result_array = JSArray::cast(result); 647 result_array = JSArray::cast(result);
628 } else { 648 } else {
629 // Allocate result array. 649 // Allocate result array.
630 Object* result = AllocateJSArray(); 650 Object* result = AllocateJSArray();
631 if (result->IsFailure()) return result; 651 if (result->IsFailure()) return result;
632 result_array = JSArray::cast(result); 652 result_array = JSArray::cast(result);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 elms->set(k, args[3 + k - actual_start], mode); 720 elms->set(k, args[3 + k - actual_start], mode);
701 } 721 }
702 722
703 // Set the length. 723 // Set the length.
704 array->set_length(Smi::FromInt(new_length)); 724 array->set_length(Smi::FromInt(new_length));
705 725
706 return result_array; 726 return result_array;
707 } 727 }
708 728
709 729
730 BUILTIN(ArrayConcat) {
731 if (!ArrayPrototypeHasNoElements()) {
732 return CallJsBuiltin("ArrayConcat", args);
733 }
734
735 // Iterate through all the arguments performing checks
736 // and calculating total length.
737 int n_arguments = args.length();
738 int result_len = 0;
739 for (int i = 0; i < n_arguments; i++) {
740 Object* arg = args[i];
741 if (!arg->IsJSArray() || !JSArray::cast(arg)->HasFastElements()) {
742 return CallJsBuiltin("ArrayConcat", args);
743 }
744
745 int len = Smi::cast(JSArray::cast(arg)->length())->value();
746
747 // We shouldn't overflow when adding another len.
748 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
749 STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
750 USE(kHalfOfMaxInt);
751 result_len += len;
752 ASSERT(result_len >= 0);
753
754 if (result_len > FixedArray::kMaxLength) {
755 return CallJsBuiltin("ArrayConcat", args);
756 }
757 }
758
759 if (result_len == 0) {
760 return AllocateEmptyJSArray();
761 }
762
763 // Allocate result.
764 Object* result = AllocateJSArray();
765 if (result->IsFailure()) return result;
766 JSArray* result_array = JSArray::cast(result);
767
768 result = Heap::AllocateUninitializedFixedArray(result_len);
769 if (result->IsFailure()) return result;
770 FixedArray* result_elms = FixedArray::cast(result);
771
772 // Copy data.
773 AssertNoAllocation no_gc;
774 int start_pos = 0;
775 for (int i = 0; i < n_arguments; i++) {
776 JSArray* array = JSArray::cast(args[i]);
777 FixedArray* elms = FixedArray::cast(array->elements());
778 int len = Smi::cast(array->length())->value();
779 CopyElements(&no_gc, result_elms, start_pos, elms, 0, len);
780 start_pos += len;
781 }
782 ASSERT(start_pos == result_len);
783
784 // Set the length and elements.
785 result_array->set_length(Smi::FromInt(result_len));
786 result_array->set_elements(result_elms);
787
788 return result_array;
789 }
790
791
710 // ----------------------------------------------------------------------------- 792 // -----------------------------------------------------------------------------
711 // 793 //
712 794
713 795
714 // Returns the holder JSObject if the function can legally be called 796 // Returns the holder JSObject if the function can legally be called
715 // with this receiver. Returns Heap::null_value() if the call is 797 // with this receiver. Returns Heap::null_value() if the call is
716 // illegal. Any arguments that don't fit the expected type is 798 // illegal. Any arguments that don't fit the expected type is
717 // overwritten with undefined. Arguments that do fit the expected 799 // overwritten with undefined. Arguments that do fit the expected
718 // type is overwritten with the object in the prototype chain that 800 // type is overwritten with the object in the prototype chain that
719 // actually has that type. 801 // actually has that type.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 841 }
760 842
761 843
762 template <bool is_construct> 844 template <bool is_construct>
763 static Object* HandleApiCallHelper( 845 static Object* HandleApiCallHelper(
764 BuiltinArguments<NEEDS_CALLED_FUNCTION> args) { 846 BuiltinArguments<NEEDS_CALLED_FUNCTION> args) {
765 ASSERT(is_construct == CalledAsConstructor()); 847 ASSERT(is_construct == CalledAsConstructor());
766 848
767 HandleScope scope; 849 HandleScope scope;
768 Handle<JSFunction> function = args.called_function(); 850 Handle<JSFunction> function = args.called_function();
851 ASSERT(function->shared()->IsApiFunction());
769 852
853 FunctionTemplateInfo* fun_data = function->shared()->get_api_func_data();
770 if (is_construct) { 854 if (is_construct) {
771 Handle<FunctionTemplateInfo> desc = 855 Handle<FunctionTemplateInfo> desc(fun_data);
772 Handle<FunctionTemplateInfo>(
773 FunctionTemplateInfo::cast(function->shared()->function_data()));
774 bool pending_exception = false; 856 bool pending_exception = false;
775 Factory::ConfigureInstance(desc, Handle<JSObject>::cast(args.receiver()), 857 Factory::ConfigureInstance(desc, Handle<JSObject>::cast(args.receiver()),
776 &pending_exception); 858 &pending_exception);
777 ASSERT(Top::has_pending_exception() == pending_exception); 859 ASSERT(Top::has_pending_exception() == pending_exception);
778 if (pending_exception) return Failure::Exception(); 860 if (pending_exception) return Failure::Exception();
861 fun_data = *desc;
779 } 862 }
780 863
781 FunctionTemplateInfo* fun_data =
782 FunctionTemplateInfo::cast(function->shared()->function_data());
783 Object* raw_holder = TypeCheck(args.length(), &args[0], fun_data); 864 Object* raw_holder = TypeCheck(args.length(), &args[0], fun_data);
784 865
785 if (raw_holder->IsNull()) { 866 if (raw_holder->IsNull()) {
786 // This function cannot be called with the given receiver. Abort! 867 // This function cannot be called with the given receiver. Abort!
787 Handle<Object> obj = 868 Handle<Object> obj =
788 Factory::NewTypeError("illegal_invocation", HandleVector(&function, 1)); 869 Factory::NewTypeError("illegal_invocation", HandleVector(&function, 1));
789 return Top::Throw(*obj); 870 return Top::Throw(*obj);
790 } 871 }
791 872
792 Object* raw_call_data = fun_data->call_code(); 873 Object* raw_call_data = fun_data->call_code();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 924
844 BUILTIN(HandleApiCallConstruct) { 925 BUILTIN(HandleApiCallConstruct) {
845 return HandleApiCallHelper<true>(args); 926 return HandleApiCallHelper<true>(args);
846 } 927 }
847 928
848 929
849 #ifdef DEBUG 930 #ifdef DEBUG
850 931
851 static void VerifyTypeCheck(Handle<JSObject> object, 932 static void VerifyTypeCheck(Handle<JSObject> object,
852 Handle<JSFunction> function) { 933 Handle<JSFunction> function) {
853 FunctionTemplateInfo* info = 934 ASSERT(function->shared()->IsApiFunction());
854 FunctionTemplateInfo::cast(function->shared()->function_data()); 935 FunctionTemplateInfo* info = function->shared()->get_api_func_data();
855 if (info->signature()->IsUndefined()) return; 936 if (info->signature()->IsUndefined()) return;
856 SignatureInfo* signature = SignatureInfo::cast(info->signature()); 937 SignatureInfo* signature = SignatureInfo::cast(info->signature());
857 Object* receiver_type = signature->receiver(); 938 Object* receiver_type = signature->receiver();
858 if (receiver_type->IsUndefined()) return; 939 if (receiver_type->IsUndefined()) return;
859 FunctionTemplateInfo* type = FunctionTemplateInfo::cast(receiver_type); 940 FunctionTemplateInfo* type = FunctionTemplateInfo::cast(receiver_type);
860 ASSERT(object->IsInstanceOf(type)); 941 ASSERT(object->IsInstanceOf(type));
861 } 942 }
862 943
863 #endif 944 #endif
864 945
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 1009
929 Handle<Object> receiver = args.at<Object>(0); 1010 Handle<Object> receiver = args.at<Object>(0);
930 1011
931 // Get the object called. 1012 // Get the object called.
932 JSObject* obj = JSObject::cast(*args.receiver()); 1013 JSObject* obj = JSObject::cast(*args.receiver());
933 1014
934 // Get the invocation callback from the function descriptor that was 1015 // Get the invocation callback from the function descriptor that was
935 // used to create the called object. 1016 // used to create the called object.
936 ASSERT(obj->map()->has_instance_call_handler()); 1017 ASSERT(obj->map()->has_instance_call_handler());
937 JSFunction* constructor = JSFunction::cast(obj->map()->constructor()); 1018 JSFunction* constructor = JSFunction::cast(obj->map()->constructor());
938 Object* template_info = constructor->shared()->function_data(); 1019 ASSERT(constructor->shared()->IsApiFunction());
939 Object* handler = 1020 Object* handler =
940 FunctionTemplateInfo::cast(template_info)->instance_call_handler(); 1021 constructor->shared()->get_api_func_data()->instance_call_handler();
941 ASSERT(!handler->IsUndefined()); 1022 ASSERT(!handler->IsUndefined());
942 CallHandlerInfo* call_data = CallHandlerInfo::cast(handler); 1023 CallHandlerInfo* call_data = CallHandlerInfo::cast(handler);
943 Object* callback_obj = call_data->callback(); 1024 Object* callback_obj = call_data->callback();
944 v8::InvocationCallback callback = 1025 v8::InvocationCallback callback =
945 v8::ToCData<v8::InvocationCallback>(callback_obj); 1026 v8::ToCData<v8::InvocationCallback>(callback_obj);
946 1027
947 // Get the data for the call and perform the callback. 1028 // Get the data for the call and perform the callback.
948 Object* data_obj = call_data->data(); 1029 Object* data_obj = call_data->data();
949 Object* result; 1030 Object* result;
950 { HandleScope scope; 1031 { HandleScope scope;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 if (entry->contains(pc)) { 1432 if (entry->contains(pc)) {
1352 return names_[i]; 1433 return names_[i];
1353 } 1434 }
1354 } 1435 }
1355 } 1436 }
1356 return NULL; 1437 return NULL;
1357 } 1438 }
1358 1439
1359 1440
1360 } } // namespace v8::internal 1441 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/cached-powers.h » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698