Commit 626cdffa authored by ager@chromium.org's avatar ager@chromium.org

Fix Array.prototype.{reduce,reduceRight} to pass undefined as receiver for strict mode callbacks.

Propagate strict mode information from pre-parser to parser for lazily compiled functions.

R=lrn@chromium.org
BUG=v8:1436
TEST=mjsunit/regress/regress-1436.js

Review URL: http://codereview.chromium.org/7044054

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8227 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 94be13e7
...@@ -1252,7 +1252,7 @@ function ArrayReduce(callback, current) { ...@@ -1252,7 +1252,7 @@ function ArrayReduce(callback, current) {
for (; i < length; i++) { for (; i < length; i++) {
var element = this[i]; var element = this[i];
if (!IS_UNDEFINED(element) || i in this) { if (!IS_UNDEFINED(element) || i in this) {
current = callback.call(null, current, element, i, this); current = callback.call(void 0, current, element, i, this);
} }
} }
return current; return current;
...@@ -1283,7 +1283,7 @@ function ArrayReduceRight(callback, current) { ...@@ -1283,7 +1283,7 @@ function ArrayReduceRight(callback, current) {
for (; i >= 0; i--) { for (; i >= 0; i--) {
var element = this[i]; var element = this[i];
if (!IS_UNDEFINED(element) || i in this) { if (!IS_UNDEFINED(element) || i in this) {
current = callback.call(null, current, element, i, this); current = callback.call(void 0, current, element, i, this);
} }
} }
return current; return current;
......
...@@ -3635,6 +3635,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, ...@@ -3635,6 +3635,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
scanner().SeekForward(end_pos - 1); scanner().SeekForward(end_pos - 1);
materialized_literal_count = entry.literal_count(); materialized_literal_count = entry.literal_count();
expected_property_count = entry.property_count(); expected_property_count = entry.property_count();
if (entry.strict_mode()) top_scope_->EnableStrictMode();
only_simple_this_property_assignments = false; only_simple_this_property_assignments = false;
this_property_assignments = isolate()->factory()->empty_fixed_array(); this_property_assignments = isolate()->factory()->empty_fixed_array();
Expect(Token::RBRACE, CHECK_OK); Expect(Token::RBRACE, CHECK_OK);
......
...@@ -72,22 +72,14 @@ class FunctionEntry BASE_EMBEDDED { ...@@ -72,22 +72,14 @@ class FunctionEntry BASE_EMBEDDED {
FunctionEntry() : backing_(Vector<unsigned>::empty()) { } FunctionEntry() : backing_(Vector<unsigned>::empty()) { }
int start_pos() { return backing_[kStartPosOffset]; } int start_pos() { return backing_[kStartPosOffset]; }
void set_start_pos(int value) { backing_[kStartPosOffset] = value; }
int end_pos() { return backing_[kEndPosOffset]; } int end_pos() { return backing_[kEndPosOffset]; }
void set_end_pos(int value) { backing_[kEndPosOffset] = value; }
int literal_count() { return backing_[kLiteralCountOffset]; } int literal_count() { return backing_[kLiteralCountOffset]; }
void set_literal_count(int value) { backing_[kLiteralCountOffset] = value; }
int property_count() { return backing_[kPropertyCountOffset]; } int property_count() { return backing_[kPropertyCountOffset]; }
void set_property_count(int value) { bool strict_mode() { return backing_[kStrictModeOffset] != 0; }
backing_[kPropertyCountOffset] = value;
}
bool is_valid() { return backing_.length() > 0; } bool is_valid() { return backing_.length() > 0; }
static const int kSize = 4; static const int kSize = 5;
private: private:
Vector<unsigned> backing_; Vector<unsigned> backing_;
...@@ -95,6 +87,7 @@ class FunctionEntry BASE_EMBEDDED { ...@@ -95,6 +87,7 @@ class FunctionEntry BASE_EMBEDDED {
static const int kEndPosOffset = 1; static const int kEndPosOffset = 1;
static const int kLiteralCountOffset = 2; static const int kLiteralCountOffset = 2;
static const int kPropertyCountOffset = 3; static const int kPropertyCountOffset = 3;
static const int kStrictModeOffset = 4;
}; };
......
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -37,7 +37,7 @@ struct PreparseDataConstants { ...@@ -37,7 +37,7 @@ struct PreparseDataConstants {
public: public:
// Layout and constants of the preparse data exchange format. // Layout and constants of the preparse data exchange format.
static const unsigned kMagicNumber = 0xBadDead; static const unsigned kMagicNumber = 0xBadDead;
static const unsigned kCurrentVersion = 6; static const unsigned kCurrentVersion = 7;
static const int kMagicOffset = 0; static const int kMagicOffset = 0;
static const int kVersionOffset = 1; static const int kVersionOffset = 1;
......
...@@ -48,7 +48,8 @@ class ParserRecorder { ...@@ -48,7 +48,8 @@ class ParserRecorder {
virtual void LogFunction(int start, virtual void LogFunction(int start,
int end, int end,
int literals, int literals,
int properties) = 0; int properties,
int strict_mode) = 0;
// Logs a symbol creation of a literal or identifier. // Logs a symbol creation of a literal or identifier.
virtual void LogAsciiSymbol(int start, Vector<const char> literal) { } virtual void LogAsciiSymbol(int start, Vector<const char> literal) { }
...@@ -84,11 +85,16 @@ class FunctionLoggingParserRecorder : public ParserRecorder { ...@@ -84,11 +85,16 @@ class FunctionLoggingParserRecorder : public ParserRecorder {
FunctionLoggingParserRecorder(); FunctionLoggingParserRecorder();
virtual ~FunctionLoggingParserRecorder() {} virtual ~FunctionLoggingParserRecorder() {}
virtual void LogFunction(int start, int end, int literals, int properties) { virtual void LogFunction(int start,
int end,
int literals,
int properties,
int strict_mode) {
function_store_.Add(start); function_store_.Add(start);
function_store_.Add(end); function_store_.Add(end);
function_store_.Add(literals); function_store_.Add(literals);
function_store_.Add(properties); function_store_.Add(properties);
function_store_.Add(strict_mode);
} }
// Logs an error message and marks the log as containing an error. // Logs an error message and marks the log as containing an error.
......
...@@ -1256,7 +1256,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(bool* ok) { ...@@ -1256,7 +1256,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(bool* ok) {
int end_pos = scanner_->location().end_pos; int end_pos = scanner_->location().end_pos;
log_->LogFunction(function_block_pos, end_pos, log_->LogFunction(function_block_pos, end_pos,
function_scope.materialized_literal_count(), function_scope.materialized_literal_count(),
function_scope.expected_properties()); function_scope.expected_properties(),
strict_mode() ? 1 : 0);
} else { } else {
ParseSourceElements(i::Token::RBRACE, CHECK_OK); ParseSourceElements(i::Token::RBRACE, CHECK_OK);
Expect(i::Token::RBRACE, CHECK_OK); Expect(i::Token::RBRACE, CHECK_OK);
......
...@@ -592,10 +592,10 @@ function GetProperty(obj, p) { ...@@ -592,10 +592,10 @@ function GetProperty(obj, p) {
// ES5 section 8.12.6 // ES5 section 8.12.6
function HasProperty(obj, p) { function HasProperty(obj, p) {
if (%IsJSProxy(obj)) { if (%IsJSProxy(obj)) {
var handler = %GetHandler(obj) var handler = %GetHandler(obj);
var has = handler.has var has = handler.has;
if (IS_UNDEFINED(has)) has = DerivedHasTrap if (IS_UNDEFINED(has)) has = DerivedHasTrap;
return ToBoolean(has.call(handler, obj, p)) return ToBoolean(has.call(handler, obj, p));
} }
var desc = GetProperty(obj, p); var desc = GetProperty(obj, p);
return IS_UNDEFINED(desc) ? false : true; return IS_UNDEFINED(desc) ? false : true;
......
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Check that reduce and reduceRight call the callback function with
// undefined as the receiver (which for non-strict functions is
// transformed to the global object).
// Check receiver for reduce and reduceRight.
var global = this;
function non_strict(){ assertEquals(global, this); }
function strict(){ "use strict"; assertEquals(void 0, this); }
function strict_null(){ "use strict"; assertEquals(null, this); }
[2, 3].reduce(non_strict);
[2, 3].reduce(strict);
[2, 3].reduceRight(non_strict);
[2, 3].reduceRight(strict);
// Check the receiver for callbacks in other array methods.
[2, 3].every(non_strict);
[2, 3].every(non_strict, undefined);
[2, 3].every(non_strict, null);
[2, 3].every(strict);
[2, 3].every(strict, undefined);
[2, 3].every(strict_null, null);
[2, 3].filter(non_strict);
[2, 3].filter(non_strict, undefined);
[2, 3].filter(non_strict, null);
[2, 3].filter(strict);
[2, 3].filter(strict, undefined);
[2, 3].filter(strict_null, null);
[2, 3].forEach(non_strict);
[2, 3].forEach(non_strict, undefined);
[2, 3].forEach(non_strict, null);
[2, 3].forEach(strict);
[2, 3].forEach(strict, undefined);
[2, 3].forEach(strict_null, null);
[2, 3].map(non_strict);
[2, 3].map(non_strict, undefined);
[2, 3].map(non_strict, null);
[2, 3].map(strict);
[2, 3].map(strict, undefined);
[2, 3].map(strict_null, null);
[2, 3].some(non_strict);
[2, 3].some(non_strict, undefined);
[2, 3].some(non_strict, null);
[2, 3].some(strict);
[2, 3].some(strict, undefined);
[2, 3].some(strict_null, null);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment