Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-09-12 16:01:50 +0300
committerAnna Henningsen <anna@addaleax.net>2018-09-17 18:20:27 +0300
commit4286dcf17f062034117043a2640b620210b61f57 (patch)
treede227e8bb7bee72778a2e7bd98f08991839bf866 /src/node_buffer.cc
parentc33e27dc3caf5a5b7954706fe6ecde1e4f82534d (diff)
src: refactor `Environment::GetCurrent()` usage
Make `Environment::GetCurrent()` return `nullptr` if the current `Context` is not a Node.js context, and for the relevant usage of this function, either: - Switch to the better `GetCurrent(args)` variant - Turn functions in to no-ops where it makes sense - Make it a `CHECK`, i.e. an API requirement, where it make sense - Leave a `TODO` comment for verifying what, if anything, is to be done PR-URL: https://github.com/nodejs/node/pull/22819 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r--src/node_buffer.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 465c4204791..dd285156b56 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -274,7 +274,9 @@ MaybeLocal<Object> New(Isolate* isolate,
MaybeLocal<Object> New(Isolate* isolate, size_t length) {
EscapableHandleScope handle_scope(isolate);
Local<Object> obj;
- if (Buffer::New(Environment::GetCurrent(isolate), length).ToLocal(&obj))
+ Environment* env = Environment::GetCurrent(isolate);
+ CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here.
+ if (Buffer::New(env, length).ToLocal(&obj))
return handle_scope.Escape(obj);
return Local<Object>();
}
@@ -316,6 +318,7 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
MaybeLocal<Object> Copy(Isolate* isolate, const char* data, size_t length) {
EscapableHandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
+ CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here.
Local<Object> obj;
if (Buffer::Copy(env, data, length).ToLocal(&obj))
return handle_scope.Escape(obj);
@@ -365,6 +368,7 @@ MaybeLocal<Object> New(Isolate* isolate,
void* hint) {
EscapableHandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
+ CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here.
Local<Object> obj;
if (Buffer::New(env, data, length, callback, hint).ToLocal(&obj))
return handle_scope.Escape(obj);
@@ -403,6 +407,7 @@ MaybeLocal<Object> New(Environment* env,
MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {
EscapableHandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
+ CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here.
Local<Object> obj;
if (Buffer::New(env, data, length).ToLocal(&obj))
return handle_scope.Escape(obj);