From 96167bf0325f116cfbe63e6838327fd570bbf1a9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 24 Feb 2016 21:57:34 +0100 Subject: [PATCH] src,tools: allow utf-8 in built-in js source code PR-URL: https://github.com/nodejs/node/pull/5418 Reviewed-By: Trevor Norris --- src/node_javascript.cc | 13 ++++++++----- tools/js2c.py | 23 +++-------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/node_javascript.cc b/src/node_javascript.cc index e8dc4ac4eaf2d2..6159cfede93810 100644 --- a/src/node_javascript.cc +++ b/src/node_javascript.cc @@ -13,11 +13,14 @@ namespace node { using v8::HandleScope; using v8::Local; +using v8::NewStringType; using v8::Object; using v8::String; Local MainSource(Environment* env) { - return OneByteString(env->isolate(), node_native, sizeof(node_native) - 1); + return String::NewFromUtf8( + env->isolate(), reinterpret_cast(node_native), + NewStringType::kNormal, sizeof(node_native) - 1).ToLocalChecked(); } void DefineJavaScript(Environment* env, Local target) { @@ -26,10 +29,10 @@ void DefineJavaScript(Environment* env, Local target) { for (int i = 0; natives[i].name; i++) { if (natives[i].source != node_native) { Local name = String::NewFromUtf8(env->isolate(), natives[i].name); - Local source = String::NewFromUtf8(env->isolate(), - natives[i].source, - String::kNormalString, - natives[i].source_len); + Local source = + String::NewFromUtf8( + env->isolate(), reinterpret_cast(natives[i].source), + NewStringType::kNormal, natives[i].source_len).ToLocalChecked(); target->Set(name, source); } } diff --git a/tools/js2c.py b/tools/js2c.py index ec9705ec6af640..9c5878a66818eb 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -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): @@ -220,7 +203,7 @@ def ReadMacros(lines): struct _native { const char* name; - const char* source; + const unsigned char* source; size_t source_len; }; @@ -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 }; """