[stubs] Fix negative index lookup in hasOwnProperty

...and HasProperty, for dictionary-elements receivers.

BUG=chromium:673008

Review-Url: https://codereview.chromium.org/2568943002
Cr-Commit-Position: refs/heads/master@{#41656}
This commit is contained in:
jkummerow 2016-12-12 12:12:18 -08:00 committed by Commit bot
parent a98d971412
commit bb753b6dd7
3 changed files with 30 additions and 0 deletions

View File

@ -48,6 +48,10 @@ void Builtins::Generate_ObjectHasOwnProperty(
&return_false, &call_runtime); &return_false, &call_runtime);
assembler.Bind(&keyisindex); assembler.Bind(&keyisindex);
// Handle negative keys in the runtime.
assembler.GotoIf(
assembler.IntPtrLessThan(var_index.value(), assembler.IntPtrConstant(0)),
&call_runtime);
assembler.TryLookupElement(object, map, instance_type, var_index.value(), assembler.TryLookupElement(object, map, instance_type, var_index.value(),
&return_true, &return_false, &call_runtime); &return_true, &return_false, &call_runtime);

View File

@ -5084,6 +5084,9 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
} }
Bind(&if_isdictionary); Bind(&if_isdictionary);
{ {
// Negative keys must be converted to property names.
GotoIf(IntPtrLessThan(intptr_index, IntPtrConstant(0)), if_bailout);
Variable var_entry(this, MachineType::PointerRepresentation()); Variable var_entry(this, MachineType::PointerRepresentation());
Node* elements = LoadElements(object); Node* elements = LoadElements(object);
NumberDictionaryLookup<SeededNumberDictionary>( NumberDictionaryLookup<SeededNumberDictionary>(

View File

@ -0,0 +1,23 @@
// Copyright 2016 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.
var a = {
"33": true,
"-1": true
};
var strkeys = Object.keys(a).map(function(k) { return "" + k });
var numkeys = Object.keys(a).map(function(k) { return +k });
var keys = strkeys.concat(numkeys);
keys.forEach(function(k) {
assertTrue(a.hasOwnProperty(k),
"property not found: " + k + "(" + (typeof k) + ")");
});
var b = {};
b.__proto__ = a;
keys.forEach(function(k) {
assertTrue(k in b, "property not found: " + k + "(" + (typeof k) + ")");
});