diff --git a/README.md b/README.md index 3893221..a761c0c 100755 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2 (`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)? )? ) | - `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)` + `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)` ) ( EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? | diff --git a/lexer.js b/lexer.js index b66e372..1bf3123 100755 --- a/lexer.js +++ b/lexer.js @@ -651,8 +651,10 @@ function tryParseObjectDefineOrKeys (keys) { if (ch !== 33/*!*/) break; pos += 1; ch = commentWhitespace(); - if (source.startsWith(id, pos)) { - pos += id.length; + if (ch === 79/*O*/ && source.startsWith('bject', pos + 1) && source[pos + 6] === '.') { + if (!tryParseObjectHasOwnProperty(it_id)) break; + } + else if (identifier()) { ch = commentWhitespace(); if (ch !== 46/*.*/) break; pos++; @@ -669,7 +671,7 @@ function tryParseObjectDefineOrKeys (keys) { if (ch !== 41/*)*/) break; pos += 1; } - else if (!tryParseObjectHasOwnProperty(it_id)) break; + else break; ch = commentWhitespace(); } if (ch !== 41/*)*/) break; diff --git a/lib/lexer.wasm b/lib/lexer.wasm index 4244f7e..2591e76 100755 Binary files a/lib/lexer.wasm and b/lib/lexer.wasm differ diff --git a/lib/lexer.wat b/lib/lexer.wat index 666c857..03a0b43 100644 --- a/lib/lexer.wat +++ b/lib/lexer.wat @@ -2879,107 +2879,113 @@ i32.const 2 i32.add i32.store offset=20540 - call 39 - drop block ;; label = @6 block ;; label = @7 - i32.const 0 - i32.load offset=20540 - local.tee 0 - local.get 2 - local.get 6 - call 65 - br_if 0 (;@7;) - i32.const 0 - local.get 0 - local.get 7 - i32.const 1 - i32.shl - i32.add - i32.store offset=20540 call 39 - i32.const 46 - i32.ne - br_if 6 (;@1;) - i32.const 0 - i32.const 0 - i32.load offset=20540 - i32.const 2 - i32.add - i32.store offset=20540 - call 39 - i32.const 104 + local.tee 0 + i32.const 79 i32.ne - br_if 6 (;@1;) + br_if 0 (;@7;) i32.const 0 i32.load offset=20540 - local.tee 0 i32.const 2 i32.add - i32.const 97 - i32.const 115 - i32.const 79 - i32.const 119 - i32.const 110 - i32.const 80 - i32.const 114 - i32.const 111 - i32.const 112 + i32.const 98 + i32.const 106 i32.const 101 - i32.const 114 + i32.const 99 i32.const 116 - i32.const 121 - call 47 + i32.const 46 + call 38 i32.eqz - br_if 6 (;@1;) - i32.const 0 - local.get 0 - i32.const 28 - i32.add - i32.store offset=20540 - call 39 - i32.const 40 - i32.ne - br_if 6 (;@1;) - i32.const 0 - i32.const 0 - i32.load offset=20540 - i32.const 2 - i32.add - i32.store offset=20540 - call 39 - drop - i32.const 0 - i32.load offset=20540 - local.tee 0 + br_if 0 (;@7;) local.get 4 - local.get 3 - call 65 - br_if 6 (;@1;) - i32.const 0 - local.get 0 local.get 8 - i32.const 1 - i32.shl - i32.add - i32.store offset=20540 - call 39 - i32.const 41 - i32.ne + call 51 + i32.eqz br_if 6 (;@1;) - i32.const 0 - i32.const 0 - i32.load offset=20540 - i32.const 2 - i32.add - i32.store offset=20540 br 1 (;@6;) end + local.get 0 + call 45 + i32.eqz + br_if 0 (;@6;) + call 39 + i32.const 46 + i32.ne + br_if 5 (;@1;) + i32.const 0 + i32.const 0 + i32.load offset=20540 + i32.const 2 + i32.add + i32.store offset=20540 + call 39 + i32.const 104 + i32.ne + br_if 5 (;@1;) + i32.const 0 + i32.load offset=20540 + local.tee 0 + i32.const 2 + i32.add + i32.const 97 + i32.const 115 + i32.const 79 + i32.const 119 + i32.const 110 + i32.const 80 + i32.const 114 + i32.const 111 + i32.const 112 + i32.const 101 + i32.const 114 + i32.const 116 + i32.const 121 + call 47 + i32.eqz + br_if 5 (;@1;) + i32.const 0 + local.get 0 + i32.const 28 + i32.add + i32.store offset=20540 + call 39 + i32.const 40 + i32.ne + br_if 5 (;@1;) + i32.const 0 + i32.const 0 + i32.load offset=20540 + i32.const 2 + i32.add + i32.store offset=20540 + call 39 + drop + i32.const 0 + i32.load offset=20540 + local.tee 0 local.get 4 + local.get 3 + call 65 + br_if 5 (;@1;) + i32.const 0 + local.get 0 local.get 8 - call 51 - i32.eqz + i32.const 1 + i32.shl + i32.add + i32.store offset=20540 + call 39 + i32.const 41 + i32.ne br_if 5 (;@1;) + i32.const 0 + i32.const 0 + i32.load offset=20540 + i32.const 2 + i32.add + i32.store offset=20540 end call 39 local.set 0 diff --git a/src/lexer.c b/src/lexer.c index e86f4b5..ce12a98 100755 --- a/src/lexer.c +++ b/src/lexer.c @@ -641,8 +641,10 @@ void tryParseObjectDefineOrKeys (bool keys) { if (ch != '!') break; pos += 1; ch = commentWhitespace(); - if (memcmp(pos, id_start, id_len * sizeof(uint16_t)) == 0) { - pos += id_len; + if (ch == 'O' && str_eq6(pos + 1, 'b', 'j', 'e', 'c', 't', '.')) { + if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break; + } + else if (identifier(ch)) { ch = commentWhitespace(); if (ch != '.') break; pos++; @@ -659,7 +661,6 @@ void tryParseObjectDefineOrKeys (bool keys) { if (ch != ')') break; pos += 1; } - else if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break; ch = commentWhitespace(); } if (ch != ')') break; diff --git a/test/_unit.js b/test/_unit.js index e1d01b6..2c215df 100755 --- a/test/_unit.js +++ b/test/_unit.js @@ -228,8 +228,13 @@ suite('Lexer', () => { if (k !== 'default' && !Object.hasOwnProperty.call(exports, k)) exports[k] = external5[k]; }); + const not = require('not'); + Object.keys(not).forEach(function (k) { + if (k !== 'default' && !a().hasOwnProperty(k)) exports[k] = not[k]; + }); + Object.keys(external6).forEach(function (k) { - if (k !== 'default' && !external6.hasOwnProperty(k)) exports[k] = external6[k]; + if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = external6[k]; }); const external𤭢 = require('external𤭢');