| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 99e6607 commit 39b8730
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const uv = process.binding('uv'); | |||
| 8 | 8 | ||
| 9 | 9 | const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap; | |
| 10 | 10 | const GetNameInfoReqWrap = cares.GetNameInfoReqWrap; | |
| 11 | + const QueryReqWrap = cares.QueryReqWrap; | ||
| 11 | 12 | ||
| 12 | 13 | const isIp = net.isIP; | |
| 13 | 14 | ||
@@ -223,12 +224,11 @@ function resolver(bindingName) { | |||
| 223 | 224 | } | |
| 224 | 225 | ||
| 225 | 226 | callback = makeAsync(callback); | |
| 226 | - var req = { | ||
| 227 | - bindingName: bindingName, | ||
| 228 | - callback: callback, | ||
| 229 | - hostname: name, | ||
| 230 | - oncomplete: onresolve | ||
| 231 | - }; | ||
| 227 | + var req = new QueryReqWrap(); | ||
| 228 | + req.bindingName = bindingName; | ||
| 229 | + req.callback = callback; | ||
| 230 | + req.hostname = name; | ||
| 231 | + req.oncomplete = onresolve; | ||
| 232 | 232 | var err = binding(req, name); | |
| 233 | 233 | if (err) throw errnoException(err, bindingName); | |
| 234 | 234 | callback.immediately = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,10 +18,11 @@ inline AsyncWrap::AsyncWrap(Environment* env, | |||
| 18 | 18 | ProviderType provider, | |
| 19 | 19 | AsyncWrap* parent) | |
| 20 | 20 | : BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1) { | |
| 21 | - // Only set wrapper class id if object will be Wrap'd. | ||
| 22 | - if (object->InternalFieldCount() > 0) | ||
| 23 | - // Shift provider value over to prevent id collision. | ||
| 24 | - persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); | ||
| 21 | + CHECK_NE(provider, PROVIDER_NONE); | ||
| 22 | + CHECK_GE(object->InternalFieldCount(), 1); | ||
| 23 | + | ||
| 24 | + // Shift provider value over to prevent id collision. | ||
| 25 | + persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); | ||
| 25 | 26 | ||
| 26 | 27 | // Check user controlled flag to see if the init callback should run. | |
| 27 | 28 | if (!env->using_asyncwrap()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,6 +85,11 @@ static void NewGetNameInfoReqWrap(const FunctionCallbackInfo<Value>& args) { | |||
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | + static void NewQueryReqWrap(const FunctionCallbackInfo<Value>& args) { | ||
| 89 | + CHECK(args.IsConstructCall()); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + | ||
| 88 | 93 | static int cmp_ares_tasks(const ares_task_t* a, const ares_task_t* b) { | |
| 89 | 94 | if (a->sock < b->sock) | |
| 90 | 95 | return -1; | |
@@ -1312,6 +1317,14 @@ static void Initialize(Local<Object> target, | |||
| 1312 | 1317 | FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap")); | |
| 1313 | 1318 | target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"), | |
| 1314 | 1319 | niw->GetFunction()); | |
| 1320 | + | ||
| 1321 | + Local<FunctionTemplate> qrw = | ||
| 1322 | + FunctionTemplate::New(env->isolate(), NewQueryReqWrap); | ||
| 1323 | + qrw->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 1324 | + qrw->SetClassName( | ||
| 1325 | + FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap")); | ||
| 1326 | + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"), | ||
| 1327 | + qrw->GetFunction()); | ||
| 1315 | 1328 | } | |
| 1316 | 1329 | ||
| 1317 | 1330 | } // namespace cares_wrap | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,6 +221,13 @@ inline Environment::Environment(v8::Local<v8::Context> context, | |||
| 221 | 221 | set_as_external(v8::External::New(isolate(), this)); | |
| 222 | 222 | set_binding_cache_object(v8::Object::New(isolate())); | |
| 223 | 223 | set_module_load_list_array(v8::Array::New(isolate())); | |
| 224 | + | ||
| 225 | + v8::Local<v8::FunctionTemplate> fn = v8::FunctionTemplate::New(isolate()); | ||
| 226 | + fn->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "InternalFieldObject")); | ||
| 227 | + v8::Local<v8::ObjectTemplate> obj = fn->InstanceTemplate(); | ||
| 228 | + obj->SetInternalFieldCount(1); | ||
| 229 | + set_generic_internal_field_template(obj); | ||
| 230 | + | ||
| 224 | 231 | RB_INIT(&cares_task_list_); | |
| 225 | 232 | handle_cleanup_waiting_ = 0; | |
| 226 | 233 | } | |
@@ -513,6 +520,12 @@ inline void Environment::SetTemplateMethod(v8::Local<v8::FunctionTemplate> that, | |||
| 513 | 520 | function->SetName(name_string); // NODE_SET_METHOD() compatibility. | |
| 514 | 521 | } | |
| 515 | 522 | ||
| 523 | + inline v8::Local<v8::Object> Environment::NewInternalFieldObject() { | ||
| 524 | + v8::MaybeLocal<v8::Object> m_obj = | ||
| 525 | + generic_internal_field_template()->NewInstance(context()); | ||
| 526 | + return m_obj.ToLocalChecked(); | ||
| 527 | + } | ||
| 528 | + | ||
| 516 | 529 | #define V(PropertyName, StringValue) \ | |
| 517 | 530 | inline \ | |
| 518 | 531 | v8::Local<v8::String> Environment::IsolateData::PropertyName() const { \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -237,6 +237,7 @@ namespace node { | |||
| 237 | 237 | V(context, v8::Context) \ | |
| 238 | 238 | V(domain_array, v8::Array) \ | |
| 239 | 239 | V(fs_stats_constructor_function, v8::Function) \ | |
| 240 | + V(generic_internal_field_template, v8::ObjectTemplate) \ | ||
| 240 | 241 | V(jsstream_constructor_template, v8::FunctionTemplate) \ | |
| 241 | 242 | V(module_load_list_array, v8::Array) \ | |
| 242 | 243 | V(pipe_constructor_template, v8::FunctionTemplate) \ | |
@@ -488,6 +489,7 @@ class Environment { | |||
| 488 | 489 | const char* name, | |
| 489 | 490 | v8::FunctionCallback callback); | |
| 490 | 491 | ||
| 492 | + inline v8::Local<v8::Object> NewInternalFieldObject(); | ||
| 491 | 493 | ||
| 492 | 494 | // Strings are shared across shared contexts. The getters simply proxy to | |
| 493 | 495 | // the per-isolate primitive. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4624,6 +4624,7 @@ class PBKDF2Request : public AsyncWrap { | |||
| 4624 | 4624 | iter_(iter) { | |
| 4625 | 4625 | if (key() == nullptr) | |
| 4626 | 4626 | FatalError("node::PBKDF2Request()", "Out of Memory"); | |
| 4627 | + Wrap(object, this); | ||
| 4627 | 4628 | } | |
| 4628 | 4629 | ||
| 4629 | 4630 | ~PBKDF2Request() override { | |
@@ -4833,7 +4834,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 4833 | 4834 | digest = EVP_sha1(); | |
| 4834 | 4835 | } | |
| 4835 | 4836 | ||
| 4836 | - obj = Object::New(env->isolate()); | ||
| 4837 | + obj = env->NewInternalFieldObject(); | ||
| 4837 | 4838 | req = new PBKDF2Request(env, | |
| 4838 | 4839 | obj, | |
| 4839 | 4840 | digest, | |
@@ -4885,6 +4886,7 @@ class RandomBytesRequest : public AsyncWrap { | |||
| 4885 | 4886 | data_(static_cast<char*>(malloc(size))) { | |
| 4886 | 4887 | if (data() == nullptr) | |
| 4887 | 4888 | FatalError("node::RandomBytesRequest()", "Out of Memory"); | |
| 4889 | + Wrap(object, this); | ||
| 4888 | 4890 | } | |
| 4889 | 4891 | ||
| 4890 | 4892 | ~RandomBytesRequest() override { | |
@@ -5001,7 +5003,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) { | |||
| 5001 | 5003 | if (size < 0 || size > Buffer::kMaxLength) | |
| 5002 | 5004 | return env->ThrowRangeError("size is not a valid Smi"); | |
| 5003 | 5005 | ||
| 5004 | - Local<Object> obj = Object::New(env->isolate()); | ||
| 5006 | + Local<Object> obj = env->NewInternalFieldObject(); | ||
| 5005 | 5007 | RandomBytesRequest* req = new RandomBytesRequest(env, obj, size); | |
| 5006 | 5008 | ||
| 5007 | 5009 | if (args[1]->IsFunction()) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments