GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — node/src/async-wrap.cc at master · chrisdew/node Expand file tree/ Copy pathasync-wrap.ccMore file actions 271 lines (205 loc) · 7.37 KB / Copy pathasync-wrap.ccFile metadata and controls271 lines (205 loc) · 7.37 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 #include "async-wrap.h" #include "async-wrap-inl.h" #include "env.h" #include "env-inl.h" #include "util.h" #include "util-inl.h" #include "v8.h" #include "v8-profiler.h" using v8::Array; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::HeapProfiler; using v8::Integer; using v8::Isolate; using v8::Local; using v8::Object; using v8::RetainedObjectInfo; using v8::TryCatch; using v8::Value; namespace node { static const char* const provider_names[] = { #define V(PROVIDER) \ #PROVIDER, NODE_ASYNC_PROVIDER_TYPES(V) #undef V }; class RetainedAsyncInfo: public RetainedObjectInfo { public: explicit RetainedAsyncInfo(uint16_t class_id, AsyncWrap* wrap); virtual void Dispose() override; virtual bool IsEquivalent(RetainedObjectInfo* other) override; virtual intptr_t GetHash() override; virtual const char* GetLabel() override; virtual intptr_t GetSizeInBytes() override; private: const char* label_; const AsyncWrap* wrap_; const int length_; }; RetainedAsyncInfo::RetainedAsyncInfo(uint16_t class_id, AsyncWrap* wrap) : label_(provider_names[class_id - NODE_ASYNC_ID_OFFSET]), wrap_(wrap), length_(wrap->self_size()) { } void RetainedAsyncInfo::Dispose() { delete this; } bool RetainedAsyncInfo::IsEquivalent(RetainedObjectInfo* other) { return label_ == other->GetLabel() && wrap_ == static_cast<RetainedAsyncInfo*>(other)->wrap_; } intptr_t RetainedAsyncInfo::GetHash() { return reinterpret_cast<intptr_t>(wrap_); } const char* RetainedAsyncInfo::GetLabel() { return label_; } intptr_t RetainedAsyncInfo::GetSizeInBytes() { return length_; } RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) { // No class_id should be the provider type of NONE. CHECK_NE(NODE_ASYNC_ID_OFFSET, class_id); CHECK(wrapper->IsObject()); CHECK(!wrapper.IsEmpty()); Local<Object> object = wrapper.As<Object>(); CHECK_GT(object->InternalFieldCount(), 0); AsyncWrap* wrap = Unwrap<AsyncWrap>(object); CHECK_NE(nullptr, wrap); return new RetainedAsyncInfo(class_id, wrap); } // end RetainedAsyncInfo static void EnableHooksJS(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Local<Function> init_fn = env->async_hooks_init_function(); if (init_fn.IsEmpty() || !init_fn->IsFunction()) return env->ThrowTypeError("init callback is not assigned to a function"); env->async_hooks()->set_enable_callbacks(1); } static void DisableHooksJS(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); env->async_hooks()->set_enable_callbacks(0); } static void SetupHooks(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); if (env->async_hooks()->callbacks_enabled()) return env->ThrowError("hooks should not be set while also enabled"); if (!args[0]->IsFunction()) return env->ThrowTypeError("init callback must be a function"); env->set_async_hooks_init_function(args[0].As<Function>()); if (args[1]->IsFunction()) env->set_async_hooks_pre_function(args[1].As<Function>()); if (args[2]->IsFunction()) env->set_async_hooks_post_function(args[2].As<Function>()); if (args[3]->IsFunction()) env->set_async_hooks_destroy_function(args[3].As<Function>()); } static void Initialize(Local<Object> target, Local<Value> unused, Local<Context> context) { Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); HandleScope scope(isolate); env->SetMethod(target, "setupHooks", SetupHooks); env->SetMethod(target, "disable", DisableHooksJS); env->SetMethod(target, "enable", EnableHooksJS); Local<Object> async_providers = Object::New(isolate); #define V(PROVIDER) \ async_providers->Set(FIXED_ONE_BYTE_STRING(isolate, #PROVIDER), \ Integer::New(isolate, AsyncWrap::PROVIDER_ ## PROVIDER)); NODE_ASYNC_PROVIDER_TYPES(V) #undef V target->Set(FIXED_ONE_BYTE_STRING(isolate, "Providers"), async_providers); env->set_async_hooks_init_function(Local<Function>()); env->set_async_hooks_pre_function(Local<Function>()); env->set_async_hooks_post_function(Local<Function>()); env->set_async_hooks_destroy_function(Local<Function>()); } void LoadAsyncWrapperInfo(Environment* env) { HeapProfiler* heap_profiler = env->isolate()->GetHeapProfiler(); #define V(PROVIDER) \ heap_profiler->SetWrapperClassInfoProvider( \ (NODE_ASYNC_ID_OFFSET + AsyncWrap::PROVIDER_ ## PROVIDER), WrapperInfo); NODE_ASYNC_PROVIDER_TYPES(V) #undef V } Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb, int argc, Local<Value>* argv) { CHECK(env()->context() == env()->isolate()->GetCurrentContext()); Local<Function> pre_fn = env()->async_hooks_pre_function(); Local<Function> post_fn = env()->async_hooks_post_function(); Local<Object> context = object(); Local<Object> process = env()->process_object(); Local<Object> domain; bool has_domain = false; if (env()->using_domains()) { Local<Value> domain_v = context->Get(env()->domain_string()); has_domain = domain_v->IsObject(); if (has_domain) { domain = domain_v.As<Object>(); if (domain->Get(env()->disposed_string())->IsTrue()) return Undefined(env()->isolate()); } } TryCatch try_catch(env()->isolate()); try_catch.SetVerbose(true); if (has_domain) { Local<Value> enter_v = domain->Get(env()->enter_string()); if (enter_v->IsFunction()) { enter_v.As<Function>()->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env()->isolate()); } } if (ran_init_callback() && !pre_fn.IsEmpty()) { try_catch.SetVerbose(false); pre_fn->Call(context, 0, nullptr); if (try_catch.HasCaught()) FatalError("node::AsyncWrap::MakeCallback", "pre hook threw"); try_catch.SetVerbose(true); } Local<Value> ret = cb->Call(context, argc, argv); if (try_catch.HasCaught()) { return Undefined(env()->isolate()); } if (ran_init_callback() && !post_fn.IsEmpty()) { try_catch.SetVerbose(false); post_fn->Call(context, 0, nullptr); if (try_catch.HasCaught()) FatalError("node::AsyncWrap::MakeCallback", "post hook threw"); try_catch.SetVerbose(true); } if (has_domain) { Local<Value> exit_v = domain->Get(env()->exit_string()); if (exit_v->IsFunction()) { exit_v.As<Function>()->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env()->isolate()); } } Environment::TickInfo* tick_info = env()->tick_info(); if (tick_info->in_tick()) { return ret; } if (tick_info->length() == 0) { env()->isolate()->RunMicrotasks(); } if (tick_info->length() == 0) { tick_info->set_index(0); return ret; } tick_info->set_in_tick(true); env()->tick_callback_function()->Call(process, 0, nullptr); tick_info->set_in_tick(false); if (try_catch.HasCaught()) { tick_info->set_last_threw(true); return Undefined(env()->isolate()); } return ret; } } // namespace node NODE_MODULE_CONTEXT_AWARE_BUILTIN(async_wrap, node::Initialize) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |