Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit f599441

Browse files
author
Face Kapow
committed
Parse V8 flags from project package.json (if available)
1 parent b9e1186 commit f599441

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

js/__loader.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@
7878
if (parsed.runtime) {
7979
if (typeof parsed.runtime === 'string') {
8080
return parsed.runtime;
81+
} else if (typeof parsed.runtime === 'object') {
82+
if (typeof parsed.runtime.main === 'string') {
83+
return parsed.runtime.main;
84+
}
85+
} else {
86+
throwError(new Error(`package.json '${packageJsonFile}' runtime (or runtime.main) field value is invalid`));
8187
}
82-
throwError(new Error(`package.json '${packageJsonFile}' runtime field value is invalid`));
8388
}
8489

8590
return parsed.main || 'index.js';

src/kernel/engines.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <kernel/system-context.h>
2424
#include <kernel/initrd.h>
2525
#include <kernel/v8platform.h>
26+
#include <string>
27+
#include <string.h>
28+
#include "../../deps/json11/json11.hpp" /*<json11.hpp>*/
2629

2730
namespace rt {
2831

@@ -69,10 +72,23 @@ class Engines {
6972

7073
v8::V8::SetEntropySource(EntropySource);
7174

72-
#if 0
73-
const char flags[] = "--expose-wasm";
74-
v8::V8::SetFlagsFromString(flags, sizeof(flags));
75-
#endif
75+
InitrdFile pkg_json = GLOBAL_initrd()->Get("/package.json");
76+
if (!pkg_json.IsEmpty()) {
77+
const char* pkg_json_cont = (const char*)pkg_json.Data();
78+
79+
std::string err;
80+
json11::Json root = json11::Json::parse(pkg_json_cont, err);
81+
if (err.empty()) {
82+
json11::Json runtime = root["runtime"];
83+
if (!runtime.is_null() && runtime.is_object()) {
84+
json11::Json v8flags = runtime["v8flags"];
85+
if (!v8flags.is_null() && v8flags.is_string()) {
86+
const char* flags_str = v8flags.string_value().c_str();
87+
v8::V8::SetFlagsFromString(flags_str, strlen(flags_str));
88+
}
89+
}
90+
}
91+
}
7692

7793
v8::V8::InitializePlatform(v8_platform_);
7894
v8::V8::Initialize();

0 commit comments

Comments
 (0)