summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-02-05 21:59:38 -0800
committerRich Trott <rtrott@gmail.com>2018-02-11 14:19:07 -0800
commitbd4773a0431da9c846c3b4a2f6459db1f151c115 (patch)
tree342d61a9d6fcf2851b821fecb21a13dc303ce00b /src
parent2aa3e3b00ff97e50f87a3345a33bcac9f424d0d7 (diff)
downloadandroid-node-v8-bd4773a0431da9c846c3b4a2f6459db1f151c115.tar.gz
android-node-v8-bd4773a0431da9c846c3b4a2f6459db1f151c115.tar.bz2
android-node-v8-bd4773a0431da9c846c3b4a2f6459db1f151c115.zip
module: use undefined if no main
If the package.json file does not have a "main" entry, return undefined rather than an empty string. This is to make more consistent behavior. For example, when package.json is a directory, "main" is undefined rather than an empty string. PR-URL: https://github.com/nodejs/node/pull/18593 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_file.cc7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 9f9c7044f9..ccb9c65cfa 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -652,9 +652,8 @@ void Close(const FunctionCallbackInfo<Value>& args) {
// Used to speed up module loading. Returns the contents of the file as
-// a string or undefined when the file cannot be opened. Returns an empty
-// string when the file does not contain the substring '"main"' because that
-// is the property we care about.
+// a string or undefined when the file cannot be opened or "main" is not found
+// in the file.
static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
uv_loop_t* loop = env->event_loop();
@@ -708,7 +707,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
const size_t size = offset - start;
if (size == 0 || size == SearchString(&chars[start], size, "\"main\"")) {
- args.GetReturnValue().SetEmptyString();
+ return;
} else {
Local<String> chars_string =
String::NewFromUtf8(env->isolate(),