fixes - buffer.indexOf polyfill + remove auto

This commit is contained in:
igor 2016-09-16 00:19:49 +03:00
parent 5315b2a17f
commit 3bbdacde29
3 changed files with 45 additions and 67 deletions

View File

@ -11,7 +11,7 @@ PR-URL: https://github.com/nodejs/node/pull/4777
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 2e8fd2c..c16be55 100644
index 2e8fd2c..1b3d618 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -18,10 +18,11 @@
@ -26,36 +26,24 @@ index 2e8fd2c..c16be55 100644
#include "base-object.h"
#include "base-object-inl.h"
#include "env.h"
@@ -55,10 +56,11 @@ using v8::PropertyCallbackInfo;
using v8::Script;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::String;
using v8::TryCatch;
+using v8::Uint8Array;
using v8::UnboundScript;
using v8::V8;
using v8::Value;
using v8::WeakCallbackData;
@@ -484,28 +486,60 @@ class ContextifyScript : public BaseObject {
@@ -484,28 +485,60 @@ class ContextifyScript : public BaseObject {
TryCatch try_catch;
Local<String> code = args[0]->ToString();
Local<String> filename = GetFilenameArg(args, 1);
bool display_errors = GetDisplayErrorsArg(args, 1);
+ Local<Uint8Array> cached_data_buf = GetCachedData(args, 1);
+ Local<Value> cached_data_buf = GetCachedData(args, 1);
+ bool produce_cached_data = GetProduceCachedData(args, 1);
if (try_catch.HasCaught()) {
try_catch.ReThrow();
return;
}
+ ScriptCompiler::CachedData* cached_data = nullptr;
+ ScriptCompiler::CachedData* cached_data = NULL;
+ if (!cached_data_buf.IsEmpty()) {
+ cached_data = new ScriptCompiler::CachedData(
+ static_cast<uint8_t*>(cached_data_buf->GetIndexedPropertiesExternalArrayData()),
+ cached_data_buf->GetIndexedPropertiesExternalArrayDataLength());
+ reinterpret_cast<uint8_t*>(Buffer::Data(cached_data_buf)),
+ Buffer::Length(cached_data_buf));
+ }
+
ScriptOrigin origin(filename);
@ -66,7 +54,7 @@ index 2e8fd2c..c16be55 100644
+ ScriptCompiler::CompileOptions compile_options =
+ ScriptCompiler::kNoCompileOptions;
+
+ if (source.GetCachedData() != nullptr)
+ if (source.GetCachedData() != NULL)
+ compile_options = ScriptCompiler::kConsumeCodeCache;
+ else if (produce_cached_data)
+ compile_options = ScriptCompiler::kProduceCodeCache;
@ -102,32 +90,32 @@ index 2e8fd2c..c16be55 100644
static bool InstanceOf(Environment* env, const Local<Value>& value) {
return !value.IsEmpty() &&
@@ -656,10 +690,46 @@ class ContextifyScript : public BaseObject {
@@ -656,10 +689,46 @@ class ContextifyScript : public BaseObject {
return value->IsUndefined() ? defaultFilename : value->ToString();
}
+ static Local<Uint8Array> GetCachedData(
+ static Local<Value> GetCachedData(
+ const FunctionCallbackInfo<Value>& args,
+ const int i) {
+ if (!args[i]->IsObject()) {
+ return Local<Uint8Array>();
+ return Local<Value>();
+ }
+ Local<String> key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "cachedData");
+ Local<Value> value = args[i].As<Object>()->Get(key);
+ if (value->IsUndefined()) {
+ return Local<Uint8Array>();
+ return Local<Value>();
+ }
+
+ if (!value->IsUint8Array()) {
+ if (!Buffer::HasInstance(value)) {
+ Environment::ThrowTypeError(
+ args.GetIsolate(),
+ "options.cachedData must be a Buffer instance");
+ return Local<Uint8Array>();
+ return Local<Value>();
+ }
+
+ return value.As<Uint8Array>();
+ return value;
+ }
+
+

View File

@ -13,10 +13,10 @@ PR-URL: https://github.com/nodejs/node/pull/5343
Reviewed-By: Fedor Indutny <fedor@indutny.com>
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index c16be55..c0a138a 100644
index 1b3d618..dfc51e9 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -528,17 +528,25 @@ class ContextifyScript : public BaseObject {
@@ -527,17 +527,25 @@ class ContextifyScript : public BaseObject {
if (compile_options == ScriptCompiler::kConsumeCodeCache) {
// no 'rejected' field in cachedData
@ -29,7 +29,7 @@ index c16be55..c0a138a 100644
- Local<String> cached_data_string = FIXED_ONE_BYTE_STRING(
- args.GetIsolate(), "cachedData");
- args.This()->Set(cached_data_string, buf);
+ bool cached_data_produced = cached_data != nullptr;
+ bool cached_data_produced = cached_data != NULL;
+ if (cached_data_produced) {
+ Local<Object> buf = Buffer::New(
+ env,

View File

@ -48,11 +48,11 @@
+
+
+void V8::FixSourcelessScript(Isolate* v8_isolate, Local<UnboundScript> script) {
+ auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ auto object = i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*script));
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ i::Handle<i::HeapObject> object = i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*script));
+ i::Handle<i::SharedFunctionInfo> function_info(
+ i::SharedFunctionInfo::cast(*object), object->GetIsolate());
+ auto s = reinterpret_cast<i::Script*>(function_info->script());
+ i::Script* s = reinterpret_cast<i::Script*>(function_info->script());
+ s->set_source(isolate->heap()->undefined_value());
+}
+
@ -76,28 +76,6 @@
ast_value_factory_ = info()->ast_value_factory();
if (ast_value_factory_ == NULL) {
ast_value_factory_ =
--- node/deps/v8/src/serialize.cc
+++ node/deps/v8/src/serialize.cc
@@ -2167,12 +2167,18 @@
payload->begin(), static_cast<size_t>(payload->length()));
}
bool SerializedCodeData::IsSane(String* source) {
- return GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
+ bool x = GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
PayloadLength() >= SharedFunctionInfo::kSize;
+ if (x) {
+ fprintf(stderr, "IsSane: true\n");
+ } else {
+ fprintf(stderr, "IsSane: false\n");
+ }
+ return x;
}
int SerializedCodeData::CheckSum(String* string) {
int checksum = Version::Hash();
--- node/lib/child_process.js
+++ node/lib/child_process.js
@@ -579,11 +579,11 @@
@ -205,20 +183,20 @@
process.nextTick(function() {
--- node/src/node_contextify.cc
+++ node/src/node_contextify.cc
@@ -488,10 +488,11 @@
@@ -487,10 +487,11 @@
Local<String> code = args[0]->ToString();
Local<String> filename = GetFilenameArg(args, 1);
bool display_errors = GetDisplayErrorsArg(args, 1);
Local<Uint8Array> cached_data_buf = GetCachedData(args, 1);
Local<Value> cached_data_buf = GetCachedData(args, 1);
bool produce_cached_data = GetProduceCachedData(args, 1);
+ bool sourceless = GetSourceless(env, args, 1);
+ bool sourceless = GetSourceless(args, 1);
if (try_catch.HasCaught()) {
try_catch.ReThrow();
return;
}
@@ -510,22 +511,37 @@
if (source.GetCachedData() != nullptr)
@@ -509,22 +510,35 @@
if (source.GetCachedData() != NULL)
compile_options = ScriptCompiler::kConsumeCodeCache;
else if (produce_cached_data)
compile_options = ScriptCompiler::kProduceCodeCache;
@ -245,9 +223,7 @@
}
+
+ if (sourceless && compile_options == ScriptCompiler::kConsumeCodeCache) {
+ if (!source.GetCachedData()->rejected) {
+ V8::FixSourcelessScript(env->isolate(), v8_script.ToLocalChecked());
+ }
+ V8::FixSourcelessScript(env->isolate(), v8_script);
+ }
+
contextify_script->script_.Reset(env->isolate(), v8_script);
@ -255,7 +231,7 @@
if (compile_options == ScriptCompiler::kConsumeCodeCache) {
// no 'rejected' field in cachedData
} else if (compile_options == ScriptCompiler::kProduceCodeCache) {
@@ -734,10 +750,23 @@
@@ -733,10 +747,23 @@
return value->IsTrue();
}
@ -281,17 +257,31 @@
TryCatch& try_catch) {
--- node/src/node_javascript.cc
+++ node/src/node_javascript.cc
@@ -53,8 +53,54 @@
@@ -53,8 +53,68 @@
String::kNormalString,
natives[i].source_len);
target->Set(name, source);
}
}
+
+ auto name = String::NewFromUtf8(env->isolate(), "_pkg_bootstrap");
+ auto source = String::NewFromUtf8(env->isolate(),
+ Local<String> name = String::NewFromUtf8(env->isolate(), "_pkg_bootstrap");
+ Handle<String> source = String::NewFromUtf8(env->isolate(),
+ "var fs = require('fs');\n" \
+ "var vm = require('vm');\n" \
+ "function indexOf(buf, value) {\n" \
+ " var match = -1;\n" \
+ " for (var i = 0; i < buf.length; i++) {\n" \
+ " if (buf[i] === value[match === -1 ? 0 : i - match]) {\n" \
+ " match = match === -1 ? i : match;\n" \
+ " if (i - match + 1 === value.length) {\n" \
+ " return match;\n" \
+ " }\n" \
+ " } else {\n" \
+ " match = -1;\n" \
+ " }\n" \
+ " }\n" \
+ " return -1;\n" \
+ "}\n" \
+ "function readOverlay() {\n" \
+ " // TODO optimize loading of overlay\n" \
+ " var me = fs.readFileSync(process.execPath);\n" \
@ -299,7 +289,7 @@
+ " 0x66, 0x2b, 0xf3, 0x41, 0xcf, 0x3c, 0xa1, 0x3e ]);\n" \
+ " sentinel[3] = 0x26; // to prevent false positive\n" \
+ " // when THIS array (mb?) found as plain bytes\n" \
+ " var start = me.indexOf(sentinel);\n" \
+ " var start = indexOf(me, sentinel);\n" \
+ " if (start < 0) {\n" \
+ " // no payload - remove entrypoint from argv[1]\n" \
+ " process.argv.splice(1, 1);\n" \