From 2808cfa41848c5a96cc585e199335b548719e95c Mon Sep 17 00:00:00 2001 From: Elliott Sprehn Date: Mon, 26 Jan 2015 11:38:04 -0800 Subject: [PATCH] module.exports should default to an empty object. Per the spec in modules.md the exports property should default to an empty object. We lazy allocate it so that modules that just replace it don't create the empty object and then throw it away. R=abarth@chromium.org Review URL: https://codereview.chromium.org/872043003 --- engine/src/flutter/tests/modules/import-without-export.sky | 6 ++++-- engine/src/flutter/tests/modules/modules-expected.txt | 7 ++++--- engine/src/flutter/tests/modules/modules.sky | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/tests/modules/import-without-export.sky b/engine/src/flutter/tests/modules/import-without-export.sky index 19415ffae3..a3eaa1ffe4 100644 --- a/engine/src/flutter/tests/modules/import-without-export.sky +++ b/engine/src/flutter/tests/modules/import-without-export.sky @@ -3,7 +3,9 @@
FAIL - Script did not execute
diff --git a/engine/src/flutter/tests/modules/modules-expected.txt b/engine/src/flutter/tests/modules/modules-expected.txt index c7bf9331b9..5bfda93db7 100644 --- a/engine/src/flutter/tests/modules/modules-expected.txt +++ b/engine/src/flutter/tests/modules/modules-expected.txt @@ -1,5 +1,6 @@ -Running 1 tests +Running 2 tests ok 1 Module should be constructable -1 tests -1 pass +ok 2 Module should have an empty object by default for exports +2 tests +2 pass 0 fail diff --git a/engine/src/flutter/tests/modules/modules.sky b/engine/src/flutter/tests/modules/modules.sky index 1e7bf94a46..baccb20e38 100644 --- a/engine/src/flutter/tests/modules/modules.sky +++ b/engine/src/flutter/tests/modules/modules.sky @@ -13,6 +13,13 @@ describe('Module', function() { assert.equal(module.document, doc2); assert.equal(module.url, "http://www.example.com/module"); }); + + it('should have an empty object by default for exports', function() { + var app = new Application(new Document(), "http://www.example.com/app"); + var module = new Module(app, new Document(), "http://www.example.com/module"); + assert.isObject(module.exports); + assert.lengthOf(Object.keys(module.exports), 0); + }); });