0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/addons/async-hooks-promise/binding.cc
Gabriel Schulhof 78286984da test,doc: make module name match gyp target name
Currently the nm_modname does not match the file name of the resulting
module. In fact, the nm_modname is pretty arbitrary. This seeks to
introduce some consistency into the nm_modname property by having the
name of the module appear in exactly one place: the "target_name"
property of the gyp target that builds the module.

PR-URL: https://github.com/nodejs/node/pull/15209
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-09-10 00:15:49 +03:00

44 lines
1.0 KiB
C++

#include <node.h>
#include <v8.h>
namespace {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::Promise;
using v8::String;
using v8::Value;
static void ThrowError(Isolate* isolate, const char* err_msg) {
Local<String> str = String::NewFromOneByte(
isolate,
reinterpret_cast<const uint8_t*>(err_msg),
NewStringType::kNormal).ToLocalChecked();
isolate->ThrowException(str);
}
static void GetPromiseField(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();
if (!args[0]->IsPromise())
return ThrowError(isolate, "arg is not an Promise");
auto p = args[0].As<Promise>();
if (p->InternalFieldCount() < 1)
return ThrowError(isolate, "Promise has no internal field");
auto l = p->GetInternalField(0);
args.GetReturnValue().Set(l);
}
inline void Initialize(v8::Local<v8::Object> binding) {
NODE_SET_METHOD(binding, "getPromiseField", GetPromiseField);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
} // anonymous namespace