MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

wire up commonjs to object_proto

+36
+6
src/esm/commonjs.c
··· 167 167 char *path_copy = strdup(module_path); 168 168 if (!path_copy) return js_mkerr(js, "OOM loading CommonJS module"); 169 169 170 + ant_value_t object_proto = js->sym.object_proto; 170 171 ant_value_t module_obj = js_mkobj(js); 171 172 ant_value_t exports_obj = js_mkobj(js); 173 + 174 + if (is_object_type(object_proto)) { 175 + js_set_proto_init(module_obj, object_proto); 176 + js_set_proto_init(exports_obj, object_proto); 177 + } 172 178 173 179 js_set(js, module_obj, "exports", exports_obj); 174 180 js_set(js, module_obj, "loaded", js_false);
+30
tests/test_cjs_exports_prototype.cjs
··· 1 + function fail(message) { 2 + console.log(`FAIL: ${message}`); 3 + process.exit(1); 4 + } 5 + 6 + if (typeof exports.__defineGetter__ !== 'function') { 7 + fail('CommonJS exports should inherit legacy accessors from Object.prototype'); 8 + } 9 + 10 + if (typeof module.__defineGetter__ !== 'function') { 11 + fail('CommonJS module should inherit legacy accessors from Object.prototype'); 12 + } 13 + 14 + exports.__defineGetter__('answer', function () { 15 + return 42; 16 + }); 17 + 18 + if (exports.answer !== 42) { 19 + fail('getter installed on exports should resolve'); 20 + } 21 + 22 + module.__defineGetter__('loadedFlag', function () { 23 + return typeof this.exports === 'object'; 24 + }); 25 + 26 + if (module.loadedFlag !== true) { 27 + fail('getter installed on module should resolve'); 28 + } 29 + 30 + console.log('PASS');