summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 20:43:29 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 20:43:29 +0000
commitb989cf8cebdd740d2618c3b32b8c45eda0006985 (patch)
tree9046b78f8f6b21ba575b8b50300e11ecadfe328f /mojo
parentfc449a93496044bde6f9c0d07017115eae16f9fa (diff)
downloadchromium_src-b989cf8cebdd740d2618c3b32b8c45eda0006985.zip
chromium_src-b989cf8cebdd740d2618c3b32b8c45eda0006985.tar.gz
chromium_src-b989cf8cebdd740d2618c3b32b8c45eda0006985.tar.bz2
Mojo: Mojom: Remove support for octal.
Don't allow octal in default (and constant) values. (Or any other values that may pop up.) R=sky@chromium.org Review URL: https://codereview.chromium.org/291173010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272311 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/apps/js/bindings/sample_service_unittests.js21
-rw-r--r--mojo/public/cpp/bindings/tests/sample_service_unittest.cc23
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_service.mojom25
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/lexer.py17
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/parser.py1
-rw-r--r--mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py2
-rw-r--r--mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py69
7 files changed, 105 insertions, 53 deletions
diff --git a/mojo/apps/js/bindings/sample_service_unittests.js b/mojo/apps/js/bindings/sample_service_unittests.js
index b61f597..83527b2 100644
--- a/mojo/apps/js/bindings/sample_service_unittests.js
+++ b/mojo/apps/js/bindings/sample_service_unittests.js
@@ -112,18 +112,15 @@ define([
// expect(full.a7).toBe(9999999999999999999);
expect(full.a8).toBe(0x12345);
expect(full.a9).toBe(-0x12345);
- // TODO(vtl): crbug.com/375829
- // expect(full.a10).toBe(8);
- // expect(full.a11).toBe(-8);
- expect(full.a12).toBe(1234);
- expect(full.a13).toBe(true);
- expect(full.a14).toBe(false);
- expect(full.a15).toBe(123.25);
- expect(full.a16).toBe(1234567890.123);
- expect(full.a17).toBe(1E10);
- expect(full.a18).toBe(-1.2E+20);
- expect(full.a19).toBe(1.23E-20);
- expect(full.a20).toBeNull();
+ expect(full.a10).toBe(1234);
+ expect(full.a11).toBe(true);
+ expect(full.a12).toBe(false);
+ expect(full.a13).toBe(123.25);
+ expect(full.a14).toBe(1234567890.123);
+ expect(full.a15).toBe(1E10);
+ expect(full.a16).toBe(-1.2E+20);
+ expect(full.a17).toBe(1.23E-20);
+ expect(full.a18).toBeNull();
// TODO(vtl): crbug.com/375845
// expect(full.a21).toBeNull();
// expect(full.a22).toBeNull();
diff --git a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
index 1cb1af4..ea32516 100644
--- a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
@@ -374,20 +374,17 @@ TEST(BindingsSampleTest, DefaultValues) {
// EXPECT_EQ(9999999999999999999ULL, full.a7());
EXPECT_EQ(0x12345, full.a8());
EXPECT_EQ(-0x12345, full.a9());
- // TODO(vtl): crbug.com/375829
- // EXPECT_EQ(8, full.a10());
- // EXPECT_EQ(-8, full.a11());
- EXPECT_EQ(1234, full.a12());
- EXPECT_TRUE(full.a13());
- EXPECT_FALSE(full.a14());
- EXPECT_FLOAT_EQ(123.25f, full.a15());
- EXPECT_DOUBLE_EQ(1234567890.123, full.a16());
- EXPECT_DOUBLE_EQ(1E10, full.a17());
- EXPECT_DOUBLE_EQ(-1.2E+20, full.a18());
- EXPECT_DOUBLE_EQ(1.23E-20, full.a19());
+ EXPECT_EQ(1234, full.a10());
+ EXPECT_TRUE(full.a11());
+ EXPECT_FALSE(full.a12());
+ EXPECT_FLOAT_EQ(123.25f, full.a13());
+ EXPECT_DOUBLE_EQ(1234567890.123, full.a14());
+ EXPECT_DOUBLE_EQ(1E10, full.a15());
+ EXPECT_DOUBLE_EQ(-1.2E+20, full.a16());
+ EXPECT_DOUBLE_EQ(1.23E-20, full.a17());
+ EXPECT_TRUE(full.a18().is_null());
+ EXPECT_TRUE(full.a19().is_null());
EXPECT_TRUE(full.a20().is_null());
- EXPECT_TRUE(full.a21().is_null());
- EXPECT_TRUE(full.a22().is_null());
}
} // namespace
diff --git a/mojo/public/interfaces/bindings/tests/sample_service.mojom b/mojo/public/interfaces/bindings/tests/sample_service.mojom
index 51e78c8..fabf2b3 100644
--- a/mojo/public/interfaces/bindings/tests/sample_service.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_service.mojom
@@ -59,23 +59,20 @@ struct DefaultsTest {
uint64 a7@7 /* = 9999999999999999999 */;
int32 a8@8 = 0x12345;
int32 a9@9 = -0x12345;
- // TODO(vtl): crbug.com/375829
- int32 a10@10 /* = 010 */; // Octal.
- int32 a11@11 /* = -010 */; // Negative octal.
- int32 a12@12 = +1234;
- bool a13@13 = true;
- bool a14@14 = false;
- float a15@15 = 123.25;
- double a16@16 = 1234567890.123;
- double a17@17 = 1E10;
- double a18@18 = -1.2E+20;
- double a19@19 = +1.23E-20;
+ int32 a10@10 = +1234;
+ bool a11@11 = true;
+ bool a12@12 = false;
+ float a13@13 = 123.25;
+ double a14@14 = 1234567890.123;
+ double a15@15 = 1E10;
+ double a16@16 = -1.2E+20;
+ double a17@17 = +1.23E-20;
// TODO(vtl): Add tests for default vs null when those are implemented (for
// structs, arrays, and strings).
- sample.DefaultsTestInner a20@20;
- uint8[] a21@21;
- string a22@22;
+ sample.DefaultsTestInner a18@18;
+ uint8[] a19@19;
+ string a20@20;
};
struct StructWithHoleV1 {
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py b/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
index f4769e7..ad13311 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
@@ -79,7 +79,7 @@ class Lexer(object):
# Constants
'ORDINAL',
- 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX',
+ 'INT_CONST_DEC', 'INT_CONST_HEX',
'FLOAT_CONST',
'CHAR_CONST',
@@ -117,10 +117,9 @@ class Lexer(object):
# integer constants (K&R2: A.2.5.1)
decimal_constant = '0|([1-9][0-9]*)'
- octal_constant = '0[0-7]+'
hex_constant = hex_prefix+hex_digits
-
- bad_octal_constant = '0[0-7]*[89]'
+ # Don't allow octal constants (even invalid octal).
+ octal_constant_disallowed = '0[0-9]+'
# character constants (K&R2: A.2.5.2)
# Note: a-zA-Z and '.-~^_!=&;,' are allowed as escape chars to support #line
@@ -219,15 +218,11 @@ class Lexer(object):
def t_INT_CONST_HEX(self, t):
return t
- @TOKEN(bad_octal_constant)
- def t_BAD_CONST_OCT(self, t):
- msg = "Invalid octal constant"
+ @TOKEN(octal_constant_disallowed)
+ def t_OCTAL_CONSTANT_DISALLOWED(self, t):
+ msg = "Octal values not allowed"
self._error(msg, t)
- @TOKEN(octal_constant)
- def t_INT_CONST_OCT(self, t):
- return t
-
@TOKEN(decimal_constant)
def t_INT_CONST_DEC(self, t):
return t
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
index 4c55e0e..694594a 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
@@ -307,7 +307,6 @@ class Parser(object):
def p_constant(self, p):
"""constant : INT_CONST_DEC
- | INT_CONST_OCT
| INT_CONST_HEX
| FLOAT_CONST
| CHAR_CONST
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
index ce553c3..a5fb37c 100644
--- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
+++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
@@ -115,8 +115,6 @@ class LexerTest(unittest.TestCase):
_MakeLexToken("ORDINAL", "@123"))
self.assertEquals(self._SingleTokenForInput("456"),
_MakeLexToken("INT_CONST_DEC", "456"))
- self.assertEquals(self._SingleTokenForInput("0765"),
- _MakeLexToken("INT_CONST_OCT", "0765"))
self.assertEquals(self._SingleTokenForInput("0x01aB2eF3"),
_MakeLexToken("INT_CONST_HEX", "0x01aB2eF3"))
self.assertEquals(self._SingleTokenForInput("123.456"),
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
index 2ee83cd..ee4d9bd 100644
--- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
+++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
@@ -433,6 +433,75 @@ struct MyStruct {
r" handle<wtf_is_this> foo;$"):
parser.Parse(source, "my_file.mojom")
+ def testValidDefaultValues(self):
+ """Tests default values that are valid (to the parser)."""
+ source = """\
+struct MyStruct {
+ int16 a0 = 0;
+ uint16 a1 = 0x0;
+ uint16 a2 = 0x00;
+ uint16 a3 = 0x01;
+ uint16 a4 = 0xcd;
+ int32 a5 = 12345;
+ int64 a6 = -12345;
+ int64 a7 = +12345;
+ uint32 a8 = 0x12cd3;
+ uint32 a9 = -0x12cD3;
+ uint32 a10 = +0x12CD3;
+ bool a11 = true;
+ bool a12 = false;
+ float a13 = 1.2345;
+ float a14 = -1.2345;
+ float a15 = +1.2345;
+ float a16 = 123.;
+ float a17 = .123;
+ double a18 = 1.23E10;
+ double a19 = 1.E-10;
+ double a20 = .5E+10;
+ double a21 = -1.23E10;
+ double a22 = +.123E10;
+};
+"""
+ expected = \
+[('MODULE',
+ '',
+ None,
+ [('STRUCT',
+ 'MyStruct',
+ None,
+ [('FIELD', 'int16', 'a0', ast.Ordinal(None), ('EXPRESSION', ['0'])),
+ ('FIELD', 'uint16', 'a1', ast.Ordinal(None), ('EXPRESSION', ['0x0'])),
+ ('FIELD', 'uint16', 'a2', ast.Ordinal(None), ('EXPRESSION', ['0x00'])),
+ ('FIELD', 'uint16', 'a3', ast.Ordinal(None), ('EXPRESSION', ['0x01'])),
+ ('FIELD', 'uint16', 'a4', ast.Ordinal(None), ('EXPRESSION', ['0xcd'])),
+ ('FIELD', 'int32', 'a5', ast.Ordinal(None), ('EXPRESSION', ['12345'])),
+ ('FIELD', 'int64', 'a6', ast.Ordinal(None),
+ ('EXPRESSION', ['-', ('EXPRESSION', ['12345'])])),
+ ('FIELD', 'int64', 'a7', ast.Ordinal(None),
+ ('EXPRESSION', ['+', ('EXPRESSION', ['12345'])])),
+ ('FIELD', 'uint32', 'a8', ast.Ordinal(None), ('EXPRESSION', ['0x12cd3'])),
+ ('FIELD', 'uint32', 'a9', ast.Ordinal(None),
+ ('EXPRESSION', ['-', ('EXPRESSION', ['0x12cD3'])])),
+ ('FIELD', 'uint32', 'a10', ast.Ordinal(None),
+ ('EXPRESSION', ['+', ('EXPRESSION', ['0x12CD3'])])),
+ ('FIELD', 'bool', 'a11', ast.Ordinal(None), ('EXPRESSION', ['true'])),
+ ('FIELD', 'bool', 'a12', ast.Ordinal(None), ('EXPRESSION', ['false'])),
+ ('FIELD', 'float', 'a13', ast.Ordinal(None), ('EXPRESSION', ['1.2345'])),
+ ('FIELD', 'float', 'a14', ast.Ordinal(None),
+ ('EXPRESSION', ['-', ('EXPRESSION', ['1.2345'])])),
+ ('FIELD', 'float', 'a15', ast.Ordinal(None),
+ ('EXPRESSION', ['+', ('EXPRESSION', ['1.2345'])])),
+ ('FIELD', 'float', 'a16', ast.Ordinal(None), ('EXPRESSION', ['123.'])),
+ ('FIELD', 'float', 'a17', ast.Ordinal(None), ('EXPRESSION', ['.123'])),
+ ('FIELD', 'double', 'a18', ast.Ordinal(None), ('EXPRESSION', ['1.23E10'])),
+ ('FIELD', 'double', 'a19', ast.Ordinal(None), ('EXPRESSION', ['1.E-10'])),
+ ('FIELD', 'double', 'a20', ast.Ordinal(None), ('EXPRESSION', ['.5E+10'])),
+ ('FIELD', 'double', 'a21', ast.Ordinal(None),
+ ('EXPRESSION', ['-', ('EXPRESSION', ['1.23E10'])])),
+ ('FIELD', 'double', 'a22', ast.Ordinal(None),
+ ('EXPRESSION', ['+', ('EXPRESSION', ['.123E10'])]))])])]
+ self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
+
if __name__ == "__main__":
unittest.main()