summaryrefslogtreecommitdiffstats
path: root/src/runtime.js
diff options
context:
space:
mode:
authorLeon Clarke <leonclarke@google.com>2010-01-19 14:06:41 +0000
committerLeon Clarke <leonclarke@google.com>2010-01-19 16:34:04 +0000
commite46be819fca9468a0cd4e74859ce0f778eb8ca60 (patch)
treef9c37105a3367f2ad5d31fbc2cb37b84fa67b59a /src/runtime.js
parentd0582a6c46733687d045e4188a1bcd0123c758a1 (diff)
downloadandroid_external_v8-e46be819fca9468a0cd4e74859ce0f778eb8ca60.tar.gz
android_external_v8-e46be819fca9468a0cd4e74859ce0f778eb8ca60.tar.bz2
android_external_v8-e46be819fca9468a0cd4e74859ce0f778eb8ca60.zip
New version of v8 from bleeding edge at revision 3649
Diffstat (limited to 'src/runtime.js')
-rw-r--r--src/runtime.js48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/runtime.js b/src/runtime.js
index 105749a7..ce2f197f 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -114,24 +114,33 @@ function STRICT_EQUALS(x) {
// ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
// the result when either (or both) the operands are NaN.
function COMPARE(x, ncr) {
- // Fast case for numbers and strings.
- if (IS_NUMBER(this) && IS_NUMBER(x)) {
- return %NumberCompare(this, x, ncr);
- }
- if (IS_STRING(this) && IS_STRING(x)) {
- return %StringCompare(this, x);
+ var left;
+
+ // Fast cases for string, numbers and undefined compares.
+ if (IS_STRING(this)) {
+ if (IS_STRING(x)) return %_StringCompare(this, x);
+ if (IS_UNDEFINED(x)) return ncr;
+ left = this;
+ } else if (IS_NUMBER(this)) {
+ if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
+ if (IS_UNDEFINED(x)) return ncr;
+ left = this;
+ } else if (IS_UNDEFINED(this)) {
+ return ncr;
+ } else {
+ if (IS_UNDEFINED(x)) return ncr;
+ left = %ToPrimitive(this, NUMBER_HINT);
}
// Default implementation.
- var a = %ToPrimitive(this, NUMBER_HINT);
- var b = %ToPrimitive(x, NUMBER_HINT);
- if (IS_STRING(a) && IS_STRING(b)) {
- return %StringCompare(a, b);
+ var right = %ToPrimitive(x, NUMBER_HINT);
+ if (IS_STRING(left) && IS_STRING(right)) {
+ return %_StringCompare(left, right);
} else {
- var a_number = %ToNumber(a);
- var b_number = %ToNumber(b);
- if (NUMBER_IS_NAN(a_number) || NUMBER_IS_NAN(b_number)) return ncr;
- return %NumberCompare(a_number, b_number, ncr);
+ var left_number = %ToNumber(left);
+ var right_number = %ToNumber(right);
+ if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
+ return %NumberCompare(left_number, right_number, ncr);
}
}
@@ -468,6 +477,17 @@ function TO_STRING() {
}
+// Specialized version of String.charAt. It assumes string as
+// the receiver type and that the index is a number.
+function STRING_CHAR_AT(pos) {
+ var char_code = %_FastCharCodeAt(this, pos);
+ if (!%_IsSmi(char_code)) {
+ return %StringCharAt(this, pos);
+ }
+ return %CharFromCode(char_code);
+}
+
+
/* -------------------------------------
- - - C o n v e r s i o n s - - -
-------------------------------------