From: lrn@chromium.org Date: Tue, 10 Aug 2010 12:44:13 +0000 (+0000) Subject: Removed support for object literal get/set with number/string property name. X-Git-Tag: upstream/4.7.83~21386 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6267578925979f1dc0ff471c05c6f13655d4ddb3;p=platform%2Fupstream%2Fv8.git Removed support for object literal get/set with number/string property name. It doesn't work correctly for array indices. Review URL: http://codereview.chromium.org/3109002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5232 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/parser.cc b/src/parser.cc index e935b7b..1df7c21 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -3587,10 +3587,8 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter, // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } // We have already read the "get" or "set" keyword. Token::Value next = Next(); - if (next == Token::IDENTIFIER || - next == Token::STRING || - next == Token::NUMBER || - Token::IsKeyword(next)) { + // TODO(820): Allow NUMBER and STRING as well (and handle array indices). + if (next == Token::IDENTIFIER || Token::IsKeyword(next)) { Handle name = factory()->LookupSymbol(scanner_.literal_string(), scanner_.literal_length()); @@ -3652,8 +3650,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { factory()->LookupSymbol(scanner_.literal_string(), scanner_.literal_length()); uint32_t index; - if (!string.is_null() && - string->AsArrayIndex(&index)) { + if (!string.is_null() && string->AsArrayIndex(&index)) { key = NewNumberLiteral(index); break; } diff --git a/src/runtime.cc b/src/runtime.cc index c7d3ff7..f9c5286 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -305,13 +305,14 @@ static Handle CreateObjectLiteralBoilerplate( } Handle result; uint32_t element_index = 0; - if (key->ToArrayIndex(&element_index)) { - // Array index (uint32). - result = SetElement(boilerplate, element_index, value); - } else if (key->IsSymbol()) { - // The key is not an array index. + if (key->IsSymbol()) { + // If key is a symbol it is not an array element. Handle name(String::cast(*key)); + ASSERT(!name->AsArrayIndex(&element_index)); result = SetProperty(boilerplate, name, value, NONE); + } else if (key->ToArrayIndex(&element_index)) { + // Array index (uint32). + result = SetElement(boilerplate, element_index, value); } else { // Non-uint32 number. ASSERT(key->IsNumber()); diff --git a/test/mjsunit/object-literal.js b/test/mjsunit/object-literal.js index 0ad1968..397d670 100644 --- a/test/mjsunit/object-literal.js +++ b/test/mjsunit/object-literal.js @@ -146,7 +146,7 @@ function testKeywordProperty(keyword) { eval("var " + keyword + " = 42;"); assertUnreachable("Not a keyword: " + keyword); } catch (e) { } - + // Simple property, read and write. var x = eval("({" + keyword + ": 42})"); assertEquals(42, x[keyword]); @@ -154,7 +154,7 @@ function testKeywordProperty(keyword) { eval("x." + keyword + " = 37"); assertEquals(37, x[keyword]); assertEquals(37, eval("x." + keyword)); - + // Getter/setter property, read and write. var y = eval("({value : 42, get " + keyword + "(){return this.value}," + " set " + keyword + "(v) { this.value = v; }})"); @@ -163,12 +163,12 @@ function testKeywordProperty(keyword) { eval("y." + keyword + " = 37"); assertEquals(37, y[keyword]); assertEquals(37, eval("y." + keyword)); - + // Quoted keyword works is read back by unquoted as well. var z = eval("({\"" + keyword + "\": 42})"); assertEquals(42, z[keyword]); assertEquals(42, eval("z." + keyword)); - + // Function property, called. var was_called; function test_call() { this.was_called = true; was_called = true; } @@ -187,26 +187,4 @@ function testKeywordProperty(keyword) { for (var i = 0; i < keywords.length; i++) { testKeywordProperty(keywords[i]); -} - -// Test getter and setter properties with string/number literal names. - -var obj = {get 42() { return 42; }, - get 3.14() { return "PI"; }, - get "PI"() { return 3.14; }, - readback: 0, - set 37(v) { this.readback = v; }, - set 1.44(v) { this.readback = v; }, - set "Poo"(v) { this.readback = v; }} - -assertEquals(42, obj[42]); -assertEquals("PI", obj[3.14]); -assertEquals(3.14, obj["PI"]); -obj[37] = "t1"; -assertEquals("t1", obj.readback); -obj[1.44] = "t2"; -assertEquals("t2", obj.readback); -obj["Poo"] = "t3"; -assertEquals("t3", obj.readback); - - +} \ No newline at end of file diff --git a/test/sputnik/sputnik.status b/test/sputnik/sputnik.status index 13108c0..bc8c1e3 100644 --- a/test/sputnik/sputnik.status +++ b/test/sputnik/sputnik.status @@ -183,8 +183,8 @@ S8.5_A2.1: PASS, FAIL if $system == linux, FAIL if $system == macos # These tests check for ES3 semantics, and differ from ES5. # When we follow ES5 semantics, it's ok to fail the test. -# Allow keywords as names of properties in object initialisers and -# in dot-notation property access. +# Allow keywords as names of properties in object initialisers and +# in dot-notation property access. S11.1.5_A4.1: FAIL_OK S11.1.5_A4.2: FAIL_OK