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

Side by Side Diff: src/runtime.js

Issue 1304633002: Correctify instanceof and make it optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Add MIPS/MIPS64 ports. Created 5 years, 3 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/objects.h ('k') | src/runtime/runtime.h » ('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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (%_IsNonNegativeSmi(this)) { 428 if (%_IsNonNegativeSmi(this)) {
429 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { 429 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) {
430 return this < x.length; 430 return this < x.length;
431 } 431 }
432 return %HasElement(x, this); 432 return %HasElement(x, this);
433 } 433 }
434 return %HasProperty(x, %$toName(this)); 434 return %HasProperty(x, %$toName(this));
435 } 435 }
436 436
437 437
438 // ECMA-262, section 11.8.6, page 54. To make the implementation more
439 // efficient, the return value should be zero if the 'this' is an
440 // instance of F, and non-zero if not. This makes it possible to avoid
441 // an expensive ToBoolean conversion in the generated code.
442 function INSTANCE_OF(F) {
443 var V = this;
444 if (!IS_SPEC_FUNCTION(F)) {
445 throw %MakeTypeError(kInstanceofFunctionExpected, F);
446 }
447
448 // If V is not an object, return false.
449 if (!IS_SPEC_OBJECT(V)) {
450 return 1;
451 }
452
453 // Check if function is bound, if so, get [[BoundFunction]] from it
454 // and use that instead of F.
455 var bindings = %BoundFunctionGetBindings(F);
456 if (bindings) {
457 F = bindings[kBoundFunctionIndex]; // Always a non-bound function.
458 }
459 // Get the prototype of F; if it is not an object, throw an error.
460 var O = F.prototype;
461 if (!IS_SPEC_OBJECT(O)) {
462 throw %MakeTypeError(kInstanceofNonobjectProto, O);
463 }
464
465 // Return whether or not O is in the prototype chain of V.
466 return %IsInPrototypeChain(O, V) ? 0 : 1;
467 }
468
469
470 function CALL_NON_FUNCTION() { 438 function CALL_NON_FUNCTION() {
471 var delegate = %GetFunctionDelegate(this); 439 var delegate = %GetFunctionDelegate(this);
472 if (!IS_FUNCTION(delegate)) { 440 if (!IS_FUNCTION(delegate)) {
473 var callsite = %RenderCallSite(); 441 var callsite = %RenderCallSite();
474 if (callsite == "") callsite = typeof this; 442 if (callsite == "") callsite = typeof this;
475 throw %MakeTypeError(kCalledNonCallable, callsite); 443 throw %MakeTypeError(kCalledNonCallable, callsite);
476 } 444 }
477 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); 445 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
478 } 446 }
479 447
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 BIT_AND_STRONG, 860 BIT_AND_STRONG,
893 BIT_XOR, 861 BIT_XOR,
894 BIT_XOR_STRONG, 862 BIT_XOR_STRONG,
895 SHL, 863 SHL,
896 SHL_STRONG, 864 SHL_STRONG,
897 SAR, 865 SAR,
898 SAR_STRONG, 866 SAR_STRONG,
899 SHR, 867 SHR,
900 SHR_STRONG, 868 SHR_STRONG,
901 IN, 869 IN,
902 INSTANCE_OF,
903 CALL_NON_FUNCTION, 870 CALL_NON_FUNCTION,
904 CALL_NON_FUNCTION_AS_CONSTRUCTOR, 871 CALL_NON_FUNCTION_AS_CONSTRUCTOR,
905 CALL_FUNCTION_PROXY, 872 CALL_FUNCTION_PROXY,
906 CALL_FUNCTION_PROXY_AS_CONSTRUCTOR, 873 CALL_FUNCTION_PROXY_AS_CONSTRUCTOR,
907 CONCAT_ITERABLE_TO_ARRAY, 874 CONCAT_ITERABLE_TO_ARRAY,
908 APPLY_PREPARE, 875 APPLY_PREPARE,
909 REFLECT_APPLY_PREPARE, 876 REFLECT_APPLY_PREPARE,
910 REFLECT_CONSTRUCT_PREPARE, 877 REFLECT_CONSTRUCT_PREPARE,
911 STACK_OVERFLOW, 878 STACK_OVERFLOW,
912 TO_NUMBER, 879 TO_NUMBER,
913 TO_STRING, 880 TO_STRING,
914 TO_NAME, 881 TO_NAME,
915 }); 882 });
916 883
917 utils.ExportToRuntime(function(to) { 884 utils.ExportToRuntime(function(to) {
918 to["to_integer_fun"] = ToInteger; 885 to["to_integer_fun"] = ToInteger;
919 to["to_length_fun"] = ToLength; 886 to["to_length_fun"] = ToLength;
920 to["to_number_fun"] = ToNumber; 887 to["to_number_fun"] = ToNumber;
921 to["to_string_fun"] = ToString; 888 to["to_string_fun"] = ToString;
922 }); 889 });
923 890
924 utils.Export(function(to) { 891 utils.Export(function(to) {
925 to.ToBoolean = ToBoolean; 892 to.ToBoolean = ToBoolean;
926 to.ToNumber = ToNumber; 893 to.ToNumber = ToNumber;
927 to.ToString = ToString; 894 to.ToString = ToString;
928 }) 895 })
929 896
930 }) 897 })
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698