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

Side by Side Diff: src/runtime.js

Issue 1337993005: [runtime] Replace the EQUALS builtin with proper Object::Equals. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michi's nit. 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-inl.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 24 matching lines...) Expand all
35 var isConcatSpreadableSymbol = 35 var isConcatSpreadableSymbol =
36 utils.ImportNow("is_concat_spreadable_symbol"); 36 utils.ImportNow("is_concat_spreadable_symbol");
37 37
38 // ---------------------------------------------------------------------------- 38 // ----------------------------------------------------------------------------
39 39
40 /* ----------------------------------- 40 /* -----------------------------------
41 - - - C o m p a r i s o n - - - 41 - - - C o m p a r i s o n - - -
42 ----------------------------------- 42 -----------------------------------
43 */ 43 */
44 44
45 // ECMA-262 Section 11.9.3.
46 function EQUALS(y) {
47 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y);
48 var x = this;
49
50 while (true) {
51 if (IS_NUMBER(x)) {
52 while (true) {
53 if (IS_NUMBER(y)) return %NumberEquals(x, y);
54 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
55 if (!IS_SPEC_OBJECT(y)) {
56 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
57 // String or boolean.
58 return %NumberEquals(x, %to_number_fun(y));
59 }
60 y = %to_primitive(y, NO_HINT);
61 }
62 } else if (IS_STRING(x)) {
63 while (true) {
64 if (IS_STRING(y)) return %StringEquals(x, y);
65 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
66 if (IS_BOOLEAN(y)) {
67 return %NumberEquals(%to_number_fun(x), %to_number_fun(y));
68 }
69 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
70 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
71 y = %to_primitive(y, NO_HINT);
72 }
73 } else if (IS_SYMBOL(x)) {
74 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
75 return 1; // not equal
76 } else if (IS_BOOLEAN(x)) {
77 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
78 if (IS_NULL_OR_UNDEFINED(y)) return 1;
79 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
80 if (IS_STRING(y)) {
81 return %NumberEquals(%to_number_fun(x), %to_number_fun(y));
82 }
83 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
84 // y is object.
85 x = %to_number_fun(x);
86 y = %to_primitive(y, NO_HINT);
87 } else if (IS_NULL_OR_UNDEFINED(x)) {
88 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
89 } else if (IS_SIMD_VALUE(x)) {
90 if (!IS_SIMD_VALUE(y)) return 1; // not equal
91 return %SimdEquals(x, y);
92 } else {
93 // x is an object.
94 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1;
95 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
96 if (IS_BOOLEAN(y)) {
97 y = %to_number_fun(y);
98 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) {
99 return 1; // not equal
100 }
101 x = %to_primitive(x, NO_HINT);
102 }
103 }
104 }
105
106
107 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as 45 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
108 // the result when either (or both) the operands are NaN. 46 // the result when either (or both) the operands are NaN.
109 function COMPARE(x, ncr) { 47 function COMPARE(x, ncr) {
110 var left; 48 var left;
111 var right; 49 var right;
112 // Fast cases for string, numbers and undefined compares. 50 // Fast cases for string, numbers and undefined compares.
113 if (IS_STRING(this)) { 51 if (IS_STRING(this)) {
114 if (IS_STRING(x)) return %_StringCompare(this, x); 52 if (IS_STRING(x)) return %_StringCompare(this, x);
115 if (IS_UNDEFINED(x)) return ncr; 53 if (IS_UNDEFINED(x)) return ncr;
116 left = this; 54 left = this;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 $toNumber = ToNumber; 429 $toNumber = ToNumber;
492 $toPositiveInteger = ToPositiveInteger; 430 $toPositiveInteger = ToPositiveInteger;
493 $toPrimitive = ToPrimitive; 431 $toPrimitive = ToPrimitive;
494 $toString = ToString; 432 $toString = ToString;
495 433
496 %InstallToContext([ 434 %InstallToContext([
497 "apply_prepare_builtin", APPLY_PREPARE, 435 "apply_prepare_builtin", APPLY_PREPARE,
498 "compare_builtin", COMPARE, 436 "compare_builtin", COMPARE,
499 "compare_strong_builtin", COMPARE_STRONG, 437 "compare_strong_builtin", COMPARE_STRONG,
500 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, 438 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY,
501 "equals_builtin", EQUALS,
502 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE, 439 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE,
503 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE, 440 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE,
504 ]); 441 ]);
505 442
506 %InstallToContext([ 443 %InstallToContext([
507 "concat_iterable_to_array", ConcatIterableToArray, 444 "concat_iterable_to_array", ConcatIterableToArray,
508 "non_number_to_number", NonNumberToNumber, 445 "non_number_to_number", NonNumberToNumber,
509 "non_string_to_string", NonStringToString, 446 "non_string_to_string", NonStringToString,
510 "to_integer_fun", ToInteger, 447 "to_integer_fun", ToInteger,
511 "to_length_fun", ToLength, 448 "to_length_fun", ToLength,
512 "to_number_fun", ToNumber, 449 "to_number_fun", ToNumber,
513 "to_primitive", ToPrimitive, 450 "to_primitive", ToPrimitive,
514 "to_string_fun", ToString, 451 "to_string_fun", ToString,
515 ]); 452 ]);
516 453
517 utils.Export(function(to) { 454 utils.Export(function(to) {
518 to.ToBoolean = ToBoolean; 455 to.ToBoolean = ToBoolean;
519 to.ToLength = ToLength; 456 to.ToLength = ToLength;
520 to.ToNumber = ToNumber; 457 to.ToNumber = ToNumber;
521 to.ToPrimitive = ToPrimitive; 458 to.ToPrimitive = ToPrimitive;
522 to.ToString = ToString; 459 to.ToString = ToString;
523 }); 460 });
524 461
525 }) 462 })
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698