Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindings: adding process.binding('builtins') method #2180

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -2281,6 +2282,10 @@ static void Binding(const FunctionCallbackInfo<Value>& 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,
Expand Down
31 changes: 31 additions & 0 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
@@ -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<Object> target,
node_module* builtins) {
HandleScope scope(env->isolate());
struct node_module* mp;
int i = 0;
Local<Array> bindings = Array::New(env->isolate(), 0);

for (mp = builtins; mp != nullptr; mp = mp->nm_link) {
Local<String> name = String::NewFromUtf8(env->isolate(), mp->nm_modname);
bindings->Set(i++, name);
}
target->Set(String::NewFromUtf8(env->isolate(), "bindings"), bindings);
}

} // namespace node
15 changes: 15 additions & 0 deletions src/node_builtins.h
Original file line number Diff line number Diff line change
@@ -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<v8::Object> target,
node_module* builtins);

} // namespace node

#endif // SRC_NODE_BUILTINS_H_