From 991ec9a7776b50285c1584781ecb70c7c7ce1214 Mon Sep 17 00:00:00 2001 From: "kasperl@chromium.org" Date: Tue, 16 Jun 2009 08:29:31 +0000 Subject: [PATCH] Make sure to invoke valueOf methods on both operands of & and >> -- even when the left operand lets us shortcut the computation. Review URL: http://codereview.chromium.org/125176 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2179 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/runtime.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/runtime.js b/src/runtime.js index ddf48f5a01..d4b49704ae 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -224,14 +224,19 @@ function BIT_AND(y) { var x; if (IS_NUMBER(this)) { x = this; + if (!IS_NUMBER(y)) y = %ToNumber(y); } else { x = %ToNumber(this); + // Make sure to convert the right operand to a number before + // bailing out in the fast case, but after converting the + // left operand. This ensures that valueOf methods on the right + // operand are always executed. + if (!IS_NUMBER(y)) y = %ToNumber(y); // Optimize for the case where we end up AND'ing a value // that doesn't convert to a number. This is common in // certain benchmarks. if (NUMBER_IS_NAN(x)) return 0; } - if (!IS_NUMBER(y)) y = %ToNumber(y); return %NumberAnd(x, y); } @@ -271,14 +276,19 @@ function SAR(y) { var x; if (IS_NUMBER(this)) { x = this; + if (!IS_NUMBER(y)) y = %ToNumber(y); } else { x = %ToNumber(this); + // Make sure to convert the right operand to a number before + // bailing out in the fast case, but after converting the + // left operand. This ensures that valueOf methods on the right + // operand are always executed. + if (!IS_NUMBER(y)) y = %ToNumber(y); // Optimize for the case where we end up shifting a value // that doesn't convert to a number. This is common in // certain benchmarks. if (NUMBER_IS_NAN(x)) return 0; } - if (!IS_NUMBER(y)) y = %ToNumber(y); return %NumberSar(x, y); }