Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Unified Diff: third_party/closure_compiler/compiler_customization_test.py

Issue 460163002: Handle property definition by {cr|Object}.defineProperty() in compiler pass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@C_compiler_pass
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/closure_compiler/compiler_customization_test.py
diff --git a/third_party/closure_compiler/compiler_customization_test.py b/third_party/closure_compiler/compiler_customization_test.py
index 99593c565fbacdba48216c5447a25c969c30e7e1..e1ad681527be7bc1238ebeb2d0b83ba2e0288c8d 100755
--- a/third_party/closure_compiler/compiler_customization_test.py
+++ b/third_party/closure_compiler/compiler_customization_test.py
@@ -23,17 +23,27 @@ class CompilerCustomizationTest(unittest.TestCase):
def setUp(self):
self._checker = Checker()
- def _runCheckerTest(self, source_code, expected_error):
+ def _runChecker(self, source_code):
file_path = "/script.js"
FileCache._cache[file_path] = source_code
- _, output = self._checker.check(file_path)
+ return self._checker.check(file_path)
+
+ def _runCheckerTestExpectError(self, source_code, expected_error):
+ _, output = self._runChecker(source_code)
self.assertTrue(expected_error in output,
msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % (
expected_error, output))
+ def _runCheckerTestExpectSuccess(self, source_code):
+ return_code, output = self._runChecker(source_code)
+
+ self.assertTrue(return_code == 0,
+ msg="Expected success, got return code %d\n\nOutput:\n%s\n" % (
+ return_code, output))
+
def testGetInstance(self):
- self._runCheckerTest(source_code="""
+ self._runCheckerTestExpectError(source_code="""
var cr = {
/** @param {!Function} ctor */
addSingletonGetter: function(ctor) {
@@ -56,7 +66,7 @@ Class.getInstance().needsNumber("wrong type");
"not match formal parameter")
def testCrDefineFunctionDefinition(self):
- self._runCheckerTest(source_code=self._CR_DEFINE_DEFINITION + """
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
cr.define('a.b.c', function() {
/** @param {number} num */
function internalName(num) {}
@@ -71,7 +81,7 @@ a.b.c.needsNumber("wrong type");
"not match formal parameter")
def testCrDefineFunctionAssignment(self):
- self._runCheckerTest(source_code=self._CR_DEFINE_DEFINITION + """
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
cr.define('a.b.c', function() {
/** @param {number} num */
var internalName = function(num) {};
@@ -86,7 +96,7 @@ a.b.c.needsNumber("wrong type");
"not match formal parameter")
def testCrDefineConstructorDefinitionPrototypeMethod(self):
- self._runCheckerTest(source_code=self._CR_DEFINE_DEFINITION + """
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
cr.define('a.b.c', function() {
/** @constructor */
function ClassInternalName() {}
@@ -106,7 +116,7 @@ new a.b.c.ClassExternalName().method("wrong type");
"prototype.method does not match formal parameter")
def testCrDefineConstructorAssignmentPrototypeMethod(self):
- self._runCheckerTest(source_code=self._CR_DEFINE_DEFINITION + """
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
cr.define('a.b.c', function() {
/** @constructor */
var ClassInternalName = function() {};
@@ -126,7 +136,7 @@ new a.b.c.ClassExternalName().method("wrong type");
"prototype.method does not match formal parameter")
def testCrDefineEnum(self):
- self._runCheckerTest(source_code=self._CR_DEFINE_DEFINITION + """
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
cr.define('a.b.c', function() {
/** @enum {string} */
var internalNameForEnum = {key: 'wrong_type'};
@@ -140,8 +150,42 @@ cr.define('a.b.c', function() {
function needsNumber(num) {}
needsNumber(a.b.c.exportedEnum.key);
-""", expected_error="ERROR - actual parameter 1 of needsNumber does not "
- "match formal parameter")
+""", expected_error="ERROR - actual parameter 1 of needsNumber does not match "
+ "formal parameter")
+
+ def testObjectDefineProperty(self):
+ self._runCheckerTestExpectSuccess("""
+/** @constructor */
+function Class() {}
+
+Object.defineProperty(Class.prototype, 'myProperty', {});
+
+alert(new Class().myProperty);
+""")
+
+ def testCrDefineProperty(self):
+ self._runCheckerTestExpectSuccess(self._CR_DEFINE_DEFINITION + """
+/** @constructor */
+function Class() {}
+
+cr.defineProperty(Class.prototype, 'myProperty', cr.PropertyKind.JS);
+
+alert(new Class().myProperty);
+""")
+
+ def testCrDefinePropertyTypeChecking(self):
+ self._runCheckerTestExpectError(source_code=self._CR_DEFINE_DEFINITION + """
+/** @constructor */
+function Class() {}
+
+cr.defineProperty(Class.prototype, 'booleanProp', cr.PropertyKind.BOOL_ATTR);
+
+/** @param {number} num */
+function needsNumber(num) {}
+
+needsNumber(new Class().booleanProp);
+""", expected_error="ERROR - actual parameter 1 of needsNumber does not match "
+ "formal parameter")
if __name__ == "__main__":

Powered by Google App Engine
This is Rietveld 408576698