Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/node_javascript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@
#include "env.h"
#include "env-inl.h"

#include <string.h>
#if !defined(_MSC_VER)
#include <strings.h>
#endif

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)).ToLocalChecked();
}

void DefineJavaScript(Environment* env, Local<Object> target) {
HandleScope scope(env->isolate());

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);
for (auto native : natives) {
if (native.source != node_native) {
Local<String> name = String::NewFromUtf8(env->isolate(), native.name);
Local<String> source =
String::NewFromUtf8(
env->isolate(), reinterpret_cast<const char*>(native.source),
NewStringType::kNormal, native.source_len).ToLocalChecked();
target->Set(name, source);
}
}
Expand Down
33 changes: 5 additions & 28 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)


def CompressScript(lines, do_jsmin):
Expand Down Expand Up @@ -220,29 +203,23 @@ 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
"""


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 };
"""


Expand Down