diff --git a/node.gyp b/node.gyp index dfa08ce6468f30..1133a19ce9db6d 100644 --- a/node.gyp +++ b/node.gyp @@ -109,6 +109,7 @@ 'src/js_stream.cc', 'src/node.cc', 'src/node_buffer.cc', + 'src/node_builtins.cc', 'src/node_constants.cc', 'src/node_contextify.cc', 'src/node_file.cc', @@ -146,6 +147,7 @@ 'src/js_stream.h', 'src/node.h', 'src/node_buffer.h', + 'src/node_builtins.h', 'src/node_constants.h', 'src/node_file.h', 'src/node_http_parser.h', diff --git a/src/node.cc b/src/node.cc index 82d081ce17aa90..d9343aa7083a72 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1,5 +1,6 @@ #include "node.h" #include "node_buffer.h" +#include "node_builtins.h" #include "node_constants.h" #include "node_file.h" #include "node_http_parser.h" @@ -2281,6 +2282,10 @@ static void Binding(const FunctionCallbackInfo& args) { exports = Object::New(env->isolate()); DefineJavaScript(env, exports); cache->Set(module, exports); + } else if (!strcmp(*module_v, "builtins")) { + exports = Object::New(env->isolate()); + DefineBuiltins(env, exports, modlist_builtin); + cache->Set(module, exports); } else { char errmsg[1024]; snprintf(errmsg, diff --git a/src/node_builtins.cc b/src/node_builtins.cc new file mode 100644 index 00000000000000..39511c2d73c390 --- /dev/null +++ b/src/node_builtins.cc @@ -0,0 +1,31 @@ +#include "node.h" +#include "v8.h" +#include "env.h" +#include "env-inl.h" + +namespace node { + +using v8::Array; +using v8::Handle; +using v8::HandleScope; +using v8::Integer; +using v8::Local; +using v8::Object; +using v8::String; + +void DefineBuiltins(Environment* env, + Handle target, + node_module* builtins) { + HandleScope scope(env->isolate()); + struct node_module* mp; + int i = 0; + Local bindings = Array::New(env->isolate(), 0); + + for (mp = builtins; mp != nullptr; mp = mp->nm_link) { + Local name = String::NewFromUtf8(env->isolate(), mp->nm_modname); + bindings->Set(i++, name); + } + target->Set(String::NewFromUtf8(env->isolate(), "bindings"), bindings); +} + +} // namespace node diff --git a/src/node_builtins.h b/src/node_builtins.h new file mode 100644 index 00000000000000..1a9ffb4584c70e --- /dev/null +++ b/src/node_builtins.h @@ -0,0 +1,15 @@ +#ifndef SRC_NODE_BUILTINS_H_ +#define SRC_NODE_BUILTINS_H_ + +#include "v8.h" +#include "env.h" + +namespace node { + +void DefineBuiltins(Environment* env, + v8::Handle target, + node_module* builtins); + +} // namespace node + +#endif // SRC_NODE_BUILTINS_H_