Skip to content

Commit

Permalink
src,tools: allow utf-8 in built-in js source code
Browse files Browse the repository at this point in the history
PR-URL: #5418
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Feb 25, 2016
1 parent 581606a commit cdc7e02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
13 changes: 8 additions & 5 deletions src/node_javascript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ namespace node {

using v8::HandleScope;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;

Local<String> MainSource(Environment* env) {
return OneByteString(env->isolate(), node_native, sizeof(node_native) - 1);
return String::NewFromUtf8(
env->isolate(), reinterpret_cast<const char*>(node_native),
NewStringType::kNormal, sizeof(node_native) - 1).ToLocalChecked();
}

void DefineJavaScript(Environment* env, Local<Object> target) {
Expand All @@ -26,10 +29,10 @@ void DefineJavaScript(Environment* env, Local<Object> target) {
for (int i = 0; natives[i].name; i++) {
if (natives[i].source != node_native) {
Local<String> name = String::NewFromUtf8(env->isolate(), natives[i].name);
Local<String> source = String::NewFromUtf8(env->isolate(),
natives[i].source,
String::kNormalString,
natives[i].source_len);
Local<String> source =
String::NewFromUtf8(
env->isolate(), reinterpret_cast<const char*>(natives[i].source),
NewStringType::kNormal, natives[i].source_len).ToLocalChecked();
target->Set(name, source);
}
}
Expand Down
23 changes: 3 additions & 20 deletions tools/js2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,7 @@


def ToCArray(filename, lines):
result = []
row = 1
col = 0
for chr in lines:
col += 1
if chr == "\n" or chr == "\r":
row += 1
col = 0

value = ord(chr)

if value >= 128:
print 'non-ascii value ' + filename + ':' + str(row) + ':' + str(col)
sys.exit(1);

result.append(str(value))
result.append("0")
return ", ".join(result)
return ','.join(str(ord(c)) for c in lines + '\0')


def CompressScript(lines, do_jsmin):
Expand Down Expand Up @@ -220,7 +203,7 @@ def ReadMacros(lines):
struct _native {
const char* name;
const char* source;
const unsigned char* source;
size_t source_len;
};
Expand All @@ -242,7 +225,7 @@ def ReadMacros(lines):
"""

SOURCE_DECLARATION = """\
const char %(escaped_id)s_native[] = { %(data)s };
const unsigned char %(escaped_id)s_native[] = { %(data)s };
"""


Expand Down

0 comments on commit cdc7e02

Please sign in to comment.