Skip to content

Commit cdc7e02

Browse files
committed
src,tools: allow utf-8 in built-in js source code
PR-URL: #5418 Reviewed-By: Trevor Norris <[email protected]>
1 parent 581606a commit cdc7e02

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

src/node_javascript.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ namespace node {
1313

1414
using v8::HandleScope;
1515
using v8::Local;
16+
using v8::NewStringType;
1617
using v8::Object;
1718
using v8::String;
1819

1920
Local<String> MainSource(Environment* env) {
20-
return OneByteString(env->isolate(), node_native, sizeof(node_native) - 1);
21+
return String::NewFromUtf8(
22+
env->isolate(), reinterpret_cast<const char*>(node_native),
23+
NewStringType::kNormal, sizeof(node_native) - 1).ToLocalChecked();
2124
}
2225

2326
void DefineJavaScript(Environment* env, Local<Object> target) {
@@ -26,10 +29,10 @@ void DefineJavaScript(Environment* env, Local<Object> target) {
2629
for (int i = 0; natives[i].name; i++) {
2730
if (natives[i].source != node_native) {
2831
Local<String> name = String::NewFromUtf8(env->isolate(), natives[i].name);
29-
Local<String> source = String::NewFromUtf8(env->isolate(),
30-
natives[i].source,
31-
String::kNormalString,
32-
natives[i].source_len);
32+
Local<String> source =
33+
String::NewFromUtf8(
34+
env->isolate(), reinterpret_cast<const char*>(natives[i].source),
35+
NewStringType::kNormal, natives[i].source_len).ToLocalChecked();
3336
target->Set(name, source);
3437
}
3538
}

tools/js2c.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,7 @@
4242

4343

4444
def ToCArray(filename, lines):
45-
result = []
46-
row = 1
47-
col = 0
48-
for chr in lines:
49-
col += 1
50-
if chr == "\n" or chr == "\r":
51-
row += 1
52-
col = 0
53-
54-
value = ord(chr)
55-
56-
if value >= 128:
57-
print 'non-ascii value ' + filename + ':' + str(row) + ':' + str(col)
58-
sys.exit(1);
59-
60-
result.append(str(value))
61-
result.append("0")
62-
return ", ".join(result)
45+
return ','.join(str(ord(c)) for c in lines + '\0')
6346

6447

6548
def CompressScript(lines, do_jsmin):
@@ -220,7 +203,7 @@ def ReadMacros(lines):
220203
221204
struct _native {
222205
const char* name;
223-
const char* source;
206+
const unsigned char* source;
224207
size_t source_len;
225208
};
226209
@@ -242,7 +225,7 @@ def ReadMacros(lines):
242225
"""
243226

244227
SOURCE_DECLARATION = """\
245-
const char %(escaped_id)s_native[] = { %(data)s };
228+
const unsigned char %(escaped_id)s_native[] = { %(data)s };
246229
"""
247230

248231

0 commit comments

Comments
 (0)