Skip to content

Commit 07e2b03

Browse files
committed
[js] Add "use strict"
1 parent ec34571 commit 07e2b03

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/vm/js/nqp-runtime/codecs.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";;
2+
class SingleByteCodec {
3+
constructor(codes) {
4+
if (codes.length !== 128 && codes.length !== 256) {
5+
throw new Error("invalid codes passed to SingleByteCodec");
6+
}
7+
8+
if (codes.length === 128) {
9+
let asciiString = "";
10+
for (var i = 0; i < 128; i++)
11+
asciiString += String.fromCharCode(i);
12+
codes = asciiString + codes;
13+
}
14+
15+
this.encodeBuf = new Buffer(65536);
16+
this.encodeBuf.fill(0);
17+
18+
// stored separately so that we can have a unmapped flag in encodeBuf
19+
this.zero = codes.charCodeAt(0);
20+
for (var i = 1; i < codes.length; i++) {
21+
//console.log(codes[i] + ": " + codes.charCodeAt(i) + ' -> ' + i);
22+
this.encodeBuf[codes.charCodeAt(i)] = i;
23+
}
24+
25+
this.decodeBuf = Buffer.from(codes, 'ucs2');
26+
}
27+
28+
encode(str) {
29+
let buf = new Buffer(str.length);
30+
for (let i = 0; i < str.length; i++) {
31+
// TODO: surrogate check
32+
const code = str.charCodeAt(i);
33+
if (code === this.zero) {
34+
buf[i] = 0;
35+
} else {
36+
const encoded = this.encodeBuf[code];
37+
if (encoded === 0) {
38+
console.log("unmapped character:", str[i]);
39+
throw new Error("unmapped character");
40+
} else {
41+
buf[i] = encoded;
42+
}
43+
}
44+
}
45+
46+
return buf;
47+
}
48+
49+
decode(buf) {
50+
}
51+
};
52+
53+
54+
const windows1252 = new SingleByteCodec("€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—˜™š›œ�žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
55+
56+
//console.log(windows1252.encode("test"));
57+
//console.log(windows1252.encode("test: ☃"));
58+
59+
module.exports.windows1252 = windows1252;

src/vm/js/nqp-runtime/core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const op = {};
24
exports.op = op;
35

@@ -218,7 +220,7 @@ exports.slurpyPos = function(currentHLL, args, from) {
218220

219221
exports.slurpyNamed = function(currentHLL, named, skip) {
220222
const hash = new Hash();
221-
for (key in named) {
223+
for (const key in named) {
222224
if (!skip[key]) {
223225
hash.content.set(key, arg(currentHLL, named[key]));
224226
}
@@ -309,7 +311,7 @@ op.captureexistsnamed = function(capture, arg) {
309311

310312
op.capturenamedshash = function(currentHLL, capture) {
311313
const hash = new Hash();
312-
for (key in capture.named) {
314+
for (const key in capture.named) {
313315
hash.content.set(key, arg(currentHLL, capture.named[key]));
314316
}
315317
return hash;

0 commit comments

Comments
 (0)