diff --git a/src/node_javascript.cc b/src/node_javascript.cc index e8dc4ac4eaf2d2..d5377047c0ec5c 100644 --- a/src/node_javascript.cc +++ b/src/node_javascript.cc @@ -4,32 +4,30 @@ #include "env.h" #include "env-inl.h" -#include -#if !defined(_MSC_VER) -#include -#endif - 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)).ToLocalChecked(); } void DefineJavaScript(Environment* env, Local target) { HandleScope scope(env->isolate()); - 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); + for (auto native : natives) { + if (native.source != node_native) { + Local name = String::NewFromUtf8(env->isolate(), native.name); + Local source = + String::NewFromUtf8( + env->isolate(), reinterpret_cast(native.source), + NewStringType::kNormal, native.source_len).ToLocalChecked(); target->Set(name, source); } } diff --git a/tools/js2c.py b/tools/js2c.py index ec9705ec6af640..3e9a1c39cc496f 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) def CompressScript(lines, do_jsmin): @@ -220,17 +203,11 @@ def ReadMacros(lines): struct _native { const char* name; - const char* source; + const unsigned char* source; size_t source_len; }; -static const struct _native natives[] = { - -%(native_lines)s\ - - { NULL, NULL, 0 } /* sentinel */ - -}; +static const struct _native natives[] = { %(native_lines)s }; } #endif @@ -238,11 +215,11 @@ def ReadMacros(lines): NATIVE_DECLARATION = """\ - { "%(id)s", %(escaped_id)s_native, sizeof(%(escaped_id)s_native)-1 }, + { "%(id)s", %(escaped_id)s_native, sizeof(%(escaped_id)s_native) }, """ SOURCE_DECLARATION = """\ - const char %(escaped_id)s_native[] = { %(data)s }; + const unsigned char %(escaped_id)s_native[] = { %(data)s }; """