[strong] no sloppy equality
R=marja@chromium.org BUG= Review URL: https://codereview.chromium.org/917703003 Cr-Commit-Position: refs/heads/master@{#26619}
This commit is contained in:
parent
e1c2e83888
commit
dff690ec07
@ -1366,7 +1366,14 @@ bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
|
||||
isolate, source_code,
|
||||
factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)),
|
||||
false);
|
||||
return CompileNative(isolate, name, source_code);
|
||||
|
||||
// TODO(rossberg): The natives do not yet obey strong mode rules
|
||||
// (for example, some macros use '==').
|
||||
bool use_strong = FLAG_use_strong;
|
||||
FLAG_use_strong = false;
|
||||
bool result = CompileNative(isolate, name, source_code);
|
||||
FLAG_use_strong = use_strong;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -840,6 +840,10 @@ void Shell::AddHistogramSample(void* histogram, int sample) {
|
||||
|
||||
void Shell::InstallUtilityScript(Isolate* isolate) {
|
||||
HandleScope scope(isolate);
|
||||
// TODO(rossberg): Utility scripts do not yet obey strong mode rules.
|
||||
bool use_strong = i::FLAG_use_strong;
|
||||
i::FLAG_use_strong = false;
|
||||
|
||||
// If we use the utility context, we have to set the security tokens so that
|
||||
// utility, evaluation and debug context can all access each other.
|
||||
v8::Local<v8::Context> utility_context =
|
||||
@ -889,6 +893,8 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
|
||||
|
||||
// Start the in-process debugger if requested.
|
||||
if (i::FLAG_debugger) v8::Debug::SetDebugEventListener(HandleDebugEvent);
|
||||
|
||||
i::FLAG_use_strong = use_strong;
|
||||
}
|
||||
#endif // !V8_SHARED
|
||||
|
||||
|
@ -161,6 +161,7 @@ var kMessages = {
|
||||
strict_cannot_assign: ["Cannot assign to read only '", "%0", "' in strict mode"],
|
||||
strict_poison_pill: ["'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them"],
|
||||
strict_caller: ["Illegal access to a strict mode caller function."],
|
||||
strong_equal: ["Please don't use '==' or '!=' in strong mode, use '===' or '!==' instead"],
|
||||
malformed_arrow_function_parameter_list: ["Malformed arrow function parameter list"],
|
||||
generator_poison_pill: ["'caller' and 'arguments' properties may not be accessed on generator functions."],
|
||||
cant_prevent_ext_external_array_elements: ["Cannot prevent extension of an object with external array elements"],
|
||||
|
@ -2440,6 +2440,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
|
||||
// prec1 >= 4
|
||||
while (Precedence(peek(), accept_IN) == prec1) {
|
||||
Token::Value op = Next();
|
||||
Scanner::Location op_location = scanner()->location();
|
||||
int pos = position();
|
||||
ExpressionT y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK);
|
||||
|
||||
@ -2459,6 +2460,11 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
|
||||
case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
|
||||
default: break;
|
||||
}
|
||||
if (cmp == Token::EQ && is_strong(language_mode())) {
|
||||
ReportMessageAt(op_location, "strong_equal");
|
||||
*ok = false;
|
||||
return this->EmptyExpression();
|
||||
}
|
||||
x = factory()->NewCompareOperation(cmp, x, y, pos);
|
||||
if (cmp != op) {
|
||||
// The comparison was negated - add a NOT.
|
||||
|
@ -161,7 +161,7 @@ void Scope::SetDefaults(ScopeType scope_type,
|
||||
scope_uses_this_ = false;
|
||||
asm_module_ = false;
|
||||
asm_function_ = outer_scope != NULL && outer_scope->asm_module_;
|
||||
// Inherit the strict mode from the parent scope.
|
||||
// Inherit the language mode from the parent scope.
|
||||
language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY;
|
||||
outer_scope_calls_sloppy_eval_ = false;
|
||||
inner_scope_calls_eval_ = false;
|
||||
@ -892,7 +892,9 @@ void Scope::Print(int n) {
|
||||
if (HasTrivialOuterContext()) {
|
||||
Indent(n1, "// scope has trivial outer context\n");
|
||||
}
|
||||
if (is_strict(language_mode())) {
|
||||
if (is_strong(language_mode())) {
|
||||
Indent(n1, "// strong mode scope\n");
|
||||
} else if (is_strict(language_mode())) {
|
||||
Indent(n1, "// strict mode scope\n");
|
||||
}
|
||||
if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
|
||||
|
14
test/mjsunit/strong/equality.js
Normal file
14
test/mjsunit/strong/equality.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2014 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --strong-mode
|
||||
|
||||
(function NoSloppyEquality() {
|
||||
assertThrows("'use strong'; 0 == 0", SyntaxError);
|
||||
assertThrows("'use strong'; 0 != 0", SyntaxError);
|
||||
assertThrows("function f() { 'use strong'; 0 == 0 }", SyntaxError);
|
||||
assertThrows("function f() { 'use strong'; 0 != 0 }", SyntaxError);
|
||||
assertTrue(eval("function f() { 'use strong' } 0 == 0"));
|
||||
assertTrue(eval("function f() { 'use strong' } 0 != 1"));
|
||||
})();
|
Loading…
Reference in New Issue
Block a user