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
This commit is contained in:
Elliott Sprehn 2015-01-26 11:38:04 -08:00
parent 966b475029
commit 2808cfa418
3 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,9 @@
<import src="../resources/dump-as-text.sky" /> <import src="../resources/dump-as-text.sky" />
<div id="result">FAIL - Script did not execute</div> <div id="result">FAIL - Script did not execute</div>
<script> <script>
document.getElementById("result").textContent = var result = "FAIL";
hello === undefined ? "PASS" : "FAIL"; if (typeof hello === "object" && Object.keys(hello).length === 0)
result = "PASS";
document.getElementById("result").textContent = result;
</script> </script>
</html> </html>

View File

@ -1,5 +1,6 @@
Running 1 tests Running 2 tests
ok 1 Module should be constructable ok 1 Module should be constructable
1 tests ok 2 Module should have an empty object by default for exports
1 pass 2 tests
2 pass
0 fail 0 fail

View File

@ -13,6 +13,13 @@ describe('Module', function() {
assert.equal(module.document, doc2); assert.equal(module.document, doc2);
assert.equal(module.url, "http://www.example.com/module"); 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);
});
}); });
</script> </script>
</html> </html>