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

Side by Side Diff: src/runtime.js

Issue 1350113002: [runtime] Replace COMPARE/COMPARE_STRONG with proper Object::Compare. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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 20 matching lines...) Expand all
31 %CheckIsBootstrapping(); 31 %CheckIsBootstrapping();
32 32
33 var GlobalArray = global.Array; 33 var GlobalArray = global.Array;
34 var GlobalBoolean = global.Boolean; 34 var GlobalBoolean = global.Boolean;
35 var GlobalString = global.String; 35 var GlobalString = global.String;
36 var isConcatSpreadableSymbol = 36 var isConcatSpreadableSymbol =
37 utils.ImportNow("is_concat_spreadable_symbol"); 37 utils.ImportNow("is_concat_spreadable_symbol");
38 38
39 // ---------------------------------------------------------------------------- 39 // ----------------------------------------------------------------------------
40 40
41 /* -----------------------------------
42 - - - C o m p a r i s o n - - -
43 -----------------------------------
44 */
45
46 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
47 // the result when either (or both) the operands are NaN.
48 function COMPARE(x, ncr) {
49 var left;
50 var right;
51 // Fast cases for string, numbers and undefined compares.
52 if (IS_STRING(this)) {
53 if (IS_STRING(x)) return %_StringCompare(this, x);
54 if (IS_UNDEFINED(x)) return ncr;
55 left = this;
56 } else if (IS_NUMBER(this)) {
57 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
58 if (IS_UNDEFINED(x)) return ncr;
59 left = this;
60 } else if (IS_UNDEFINED(this)) {
61 if (!IS_UNDEFINED(x)) {
62 %to_primitive(x, NUMBER_HINT);
63 }
64 return ncr;
65 } else if (IS_UNDEFINED(x)) {
66 %to_primitive(this, NUMBER_HINT);
67 return ncr;
68 } else {
69 left = %to_primitive(this, NUMBER_HINT);
70 }
71
72 right = %to_primitive(x, NUMBER_HINT);
73 if (IS_STRING(left) && IS_STRING(right)) {
74 return %_StringCompare(left, right);
75 } else {
76 var left_number = %to_number_fun(left);
77 var right_number = %to_number_fun(right);
78 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
79 return %NumberCompare(left_number, right_number, ncr);
80 }
81 }
82
83 // Strong mode COMPARE throws if an implicit conversion would be performed
84 function COMPARE_STRONG(x, ncr) {
85 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x);
86 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
87
88 throw %make_type_error(kStrongImplicitConversion);
89 }
90
91
92 /* ----------------------------- 41 /* -----------------------------
93 - - - H e l p e r s - - - 42 - - - H e l p e r s - - -
94 ----------------------------- 43 -----------------------------
95 */ 44 */
96 45
97 function APPLY_PREPARE(args) { 46 function APPLY_PREPARE(args) {
98 var length; 47 var length;
99 48
100 // First check that the receiver is callable. 49 // First check that the receiver is callable.
101 if (!IS_CALLABLE(this)) { 50 if (!IS_CALLABLE(this)) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 $sameValueZero = SameValueZero; 375 $sameValueZero = SameValueZero;
427 $toInteger = ToInteger; 376 $toInteger = ToInteger;
428 $toLength = ToLength; 377 $toLength = ToLength;
429 $toNumber = ToNumber; 378 $toNumber = ToNumber;
430 $toPositiveInteger = ToPositiveInteger; 379 $toPositiveInteger = ToPositiveInteger;
431 $toPrimitive = ToPrimitive; 380 $toPrimitive = ToPrimitive;
432 $toString = ToString; 381 $toString = ToString;
433 382
434 %InstallToContext([ 383 %InstallToContext([
435 "apply_prepare_builtin", APPLY_PREPARE, 384 "apply_prepare_builtin", APPLY_PREPARE,
436 "compare_builtin", COMPARE,
437 "compare_strong_builtin", COMPARE_STRONG,
438 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, 385 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY,
439 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE, 386 "reflect_apply_prepare_builtin", REFLECT_APPLY_PREPARE,
440 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE, 387 "reflect_construct_prepare_builtin", REFLECT_CONSTRUCT_PREPARE,
441 ]); 388 ]);
442 389
443 %InstallToContext([ 390 %InstallToContext([
444 "concat_iterable_to_array", ConcatIterableToArray, 391 "concat_iterable_to_array", ConcatIterableToArray,
445 "non_number_to_number", NonNumberToNumber, 392 "non_number_to_number", NonNumberToNumber,
446 "non_string_to_string", NonStringToString, 393 "non_string_to_string", NonStringToString,
447 "to_integer_fun", ToInteger, 394 "to_integer_fun", ToInteger,
448 "to_length_fun", ToLength, 395 "to_length_fun", ToLength,
449 "to_number_fun", ToNumber, 396 "to_number_fun", ToNumber,
450 "to_primitive", ToPrimitive, 397 "to_primitive", ToPrimitive,
451 "to_string_fun", ToString, 398 "to_string_fun", ToString,
452 ]); 399 ]);
453 400
454 utils.Export(function(to) { 401 utils.Export(function(to) {
455 to.ToBoolean = ToBoolean; 402 to.ToBoolean = ToBoolean;
456 to.ToLength = ToLength; 403 to.ToLength = ToLength;
457 to.ToNumber = ToNumber; 404 to.ToNumber = ToNumber;
458 to.ToPrimitive = ToPrimitive; 405 to.ToPrimitive = ToPrimitive;
459 to.ToString = ToString; 406 to.ToString = ToString;
460 }); 407 });
461 408
462 }) 409 })
OLDNEW
« src/objects.cc ('K') | « src/objects-inl.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698