mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: support UTF-8 in compiled-in JS source files
Detect it when source files in lib/ are not ASCII. Decode them as UTF-8 and store them as UTF-16 in the binary so they can be used as external string resources without non-ASCII characters getting mangled. Fixes: https://github.com/nodejs/node/issues/10673 PR-URL: https://github.com/nodejs/node/pull/11129 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
5350f04e42
commit
3380cd5fdb
3 files changed
+85
-99
No files matched your search
@@ -1,51 +0,0 @@
|
||||
#include "node.h"
|
||||
#include "node_natives.h"
|
||||
#include "v8.h"
|
||||
#include "env.h"
|
||||
#include "env-inl.h"
|
||||
|
||||
namespace node {
|
||||
|
||||
using v8::Local;
|
||||
using v8::NewStringType;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
|
||||
// id##_data is defined in node_natives.h.
|
||||
#define V(id) \
|
||||
static struct : public String::ExternalOneByteStringResource { \
|
||||
const char* data() const override { \
|
||||
return reinterpret_cast<const char*>(id##_data); \
|
||||
} \
|
||||
size_t length() const override { return sizeof(id##_data); } \
|
||||
void Dispose() override { /* Default calls `delete this`. */ } \
|
||||
} id##_external_data;
|
||||
NODE_NATIVES_MAP(V)
|
||||
#undef V
|
||||
|
||||
Local<String> MainSource(Environment* env) {
|
||||
auto maybe_string =
|
||||
String::NewExternalOneByte(
|
||||
env->isolate(),
|
||||
&internal_bootstrap_node_external_data);
|
||||
return maybe_string.ToLocalChecked();
|
||||
}
|
||||
|
||||
void DefineJavaScript(Environment* env, Local<Object> target) {
|
||||
auto context = env->context();
|
||||
#define V(id) \
|
||||
do { \
|
||||
auto key = \
|
||||
String::NewFromOneByte( \
|
||||
env->isolate(), id##_name, NewStringType::kNormal, \
|
||||
sizeof(id##_name)).ToLocalChecked(); \
|
||||
auto value = \
|
||||
String::NewExternalOneByte( \
|
||||
env->isolate(), &id##_external_data).ToLocalChecked(); \
|
||||
CHECK(target->Set(context, key, value).FromJust()); \
|
||||
} while (0);
|
||||
NODE_NATIVES_MAP(V)
|
||||
#undef V
|
||||
}
|
||||
|
||||
} // namespace node
|
||||
Reference in new issue
Block a user