GeezerVison is showing github.com — src: no abort from getter if object isn't wrapped · outsideris/node@c0e6c66
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/base-object-inl.h +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,10 @@ inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle) | 14 | 14 | : handle_(env->isolate(), handle), | 15 | 15 | env_(env) { | 16 | 16 | CHECK_EQ(false, handle.IsEmpty()); | | 17 | + // The zero field holds a pointer to the handle. Immediately set it to | | 18 | + // nullptr in case it's accessed by the user before construction is complete. | | 19 | + if (handle->InternalFieldCount() > 0) | | 20 | + handle->SetAlignedPointerInInternalField(0, nullptr); | 17 | 21 | } | 18 | 22 |
| 19 | 23 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/fs_event_wrap.cc +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,7 +86,8 @@ void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) { | 86 | 86 | void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) { | 87 | 87 | Environment* env = Environment::GetCurrent(args); | 88 | 88 |
| 89 | | - FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder()); | | 89 | + FSEventWrap* wrap; | | 90 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 90 | 91 |
| 91 | 92 | static const char kErrMsg[] = "filename must be a string or Buffer"; | 92 | 93 | if (args.Length() < 1) | @@ -181,7 +182,8 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, | 181 | 182 |
| 182 | 183 |
| 183 | 184 | void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) { | 184 | | - FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder()); | | 185 | + FSEventWrap* wrap; | | 186 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 185 | 187 |
| 186 | 188 | if (wrap == nullptr || wrap->initialized_ == false) | 187 | 189 | return; | |
Collapse file Copy file name to clipboardExpand all lines: src/handle_wrap.cc +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,31 +18,35 @@ using v8::Value; | 18 | 18 |
| 19 | 19 |
| 20 | 20 | void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { | 21 | | - HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); | | 21 | + HandleWrap* wrap; | | 22 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 22 | 23 |
| 23 | 24 | if (IsAlive(wrap)) | 24 | 25 | uv_ref(wrap->GetHandle()); | 25 | 26 | } | 26 | 27 |
| 27 | 28 |
| 28 | 29 | void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { | 29 | | - HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); | | 30 | + HandleWrap* wrap; | | 31 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 30 | 32 |
| 31 | 33 | if (IsAlive(wrap)) | 32 | 34 | uv_unref(wrap->GetHandle()); | 33 | 35 | } | 34 | 36 |
| 35 | 37 |
| 36 | 38 | void HandleWrap::HasRef(const FunctionCallbackInfo<Value>& args) { | 37 | | - HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); | | 39 | + HandleWrap* wrap; | | 40 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 38 | 41 | args.GetReturnValue().Set(HasRef(wrap)); | 39 | 42 | } | 40 | 43 |
| 41 | 44 |
| 42 | 45 | void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { | 43 | 46 | Environment* env = Environment::GetCurrent(args); | 44 | 47 |
| 45 | | - HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); | | 48 | + HandleWrap* wrap; | | 49 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 46 | 50 |
| 47 | 51 | // Guard against uninitialized handle or double close. | 48 | 52 | if (!IsAlive(wrap)) | |
Collapse file Copy file name to clipboardExpand all lines: src/js_stream.cc +16-7Lines changed: 16 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -135,7 +135,8 @@ static void FreeCallback(char* data, void* hint) { | 135 | 135 |
| 136 | 136 |
| 137 | 137 | void JSStream::DoAlloc(const FunctionCallbackInfo<Value>& args) { | 138 | | - JSStream* wrap = Unwrap<JSStream>(args.Holder()); | | 138 | + JSStream* wrap; | | 139 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 139 | 140 |
| 140 | 141 | uv_buf_t buf; | 141 | 142 | wrap->OnAlloc(args[0]->Int32Value(), &buf); | @@ -150,7 +151,8 @@ void JSStream::DoAlloc(const FunctionCallbackInfo<Value>& args) { | 150 | 151 |
| 151 | 152 |
| 152 | 153 | void JSStream::DoRead(const FunctionCallbackInfo<Value>& args) { | 153 | | - JSStream* wrap = Unwrap<JSStream>(args.Holder()); | | 154 | + JSStream* wrap; | | 155 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 154 | 156 |
| 155 | 157 | CHECK(Buffer::HasInstance(args[1])); | 156 | 158 | uv_buf_t buf = uv_buf_init(Buffer::Data(args[1]), Buffer::Length(args[1])); | @@ -159,23 +161,29 @@ void JSStream::DoRead(const FunctionCallbackInfo<Value>& args) { | 159 | 161 |
| 160 | 162 |
| 161 | 163 | void JSStream::DoAfterWrite(const FunctionCallbackInfo<Value>& args) { | 162 | | - JSStream* wrap = Unwrap<JSStream>(args.Holder()); | 163 | | - WriteWrap* w = Unwrap<WriteWrap>(args[0].As<Object>()); | | 164 | + JSStream* wrap; | | 165 | + CHECK(args[0]->IsObject()); | | 166 | + WriteWrap* w; | | 167 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | | 168 | + ASSIGN_OR_RETURN_UNWRAP(&w, args[0].As<Object>()); | 164 | 169 |
| 165 | 170 | wrap->OnAfterWrite(w); | 166 | 171 | } | 167 | 172 |
| 168 | 173 |
| 169 | 174 | template <class Wrap> | 170 | 175 | void JSStream::Finish(const FunctionCallbackInfo<Value>& args) { | 171 | | - Wrap* w = Unwrap<Wrap>(args[0].As<Object>()); | | 176 | + Wrap* w; | | 177 | + CHECK(args[0]->IsObject()); | | 178 | + ASSIGN_OR_RETURN_UNWRAP(&w, args[0].As<Object>()); | 172 | 179 |
| 173 | 180 | w->Done(args[1]->Int32Value()); | 174 | 181 | } | 175 | 182 |
| 176 | 183 |
| 177 | 184 | void JSStream::ReadBuffer(const FunctionCallbackInfo<Value>& args) { | 178 | | - JSStream* wrap = Unwrap<JSStream>(args.Holder()); | | 185 | + JSStream* wrap; | | 186 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 179 | 187 |
| 180 | 188 | CHECK(Buffer::HasInstance(args[0])); | 181 | 189 | char* data = Buffer::Data(args[0]); | @@ -197,7 +205,8 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo<Value>& args) { | 197 | 205 |
| 198 | 206 |
| 199 | 207 | void JSStream::EmitEOF(const FunctionCallbackInfo<Value>& args) { | 200 | | - JSStream* wrap = Unwrap<JSStream>(args.Holder()); | | 208 | + JSStream* wrap; | | 209 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | 201 | 210 |
| 202 | 211 | wrap->OnRead(UV_EOF, nullptr); | 203 | 212 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_contextify.cc +12-11Lines changed: 12 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -343,8 +343,8 @@ class ContextifyContext { | 343 | 343 | static void GlobalPropertyGetterCallback( | 344 | 344 | Local<Name> property, | 345 | 345 | const PropertyCallbackInfo<Value>& args) { | 346 | | - ContextifyContext* ctx = | 347 | | - Unwrap<ContextifyContext>(args.Data().As<Object>()); | | 346 | + ContextifyContext* ctx; | | 347 | + ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>()); | 348 | 348 |
| 349 | 349 | // Stil initializing | 350 | 350 | if (ctx->context_.IsEmpty()) | @@ -373,8 +373,8 @@ class ContextifyContext { | 373 | 373 | Local<Name> property, | 374 | 374 | Local<Value> value, | 375 | 375 | const PropertyCallbackInfo<Value>& args) { | 376 | | - ContextifyContext* ctx = | 377 | | - Unwrap<ContextifyContext>(args.Data().As<Object>()); | | 376 | + ContextifyContext* ctx; | | 377 | + ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>()); | 378 | 378 |
| 379 | 379 | // Stil initializing | 380 | 380 | if (ctx->context_.IsEmpty()) | @@ -387,8 +387,8 @@ class ContextifyContext { | 387 | 387 | static void GlobalPropertyQueryCallback( | 388 | 388 | Local<Name> property, | 389 | 389 | const PropertyCallbackInfo<Integer>& args) { | 390 | | - ContextifyContext* ctx = | 391 | | - Unwrap<ContextifyContext>(args.Data().As<Object>()); | | 390 | + ContextifyContext* ctx; | | 391 | + ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>()); | 392 | 392 |
| 393 | 393 | // Stil initializing | 394 | 394 | if (ctx->context_.IsEmpty()) | @@ -414,8 +414,8 @@ class ContextifyContext { | 414 | 414 | static void GlobalPropertyDeleterCallback( | 415 | 415 | Local<Name> property, | 416 | 416 | const PropertyCallbackInfo<Boolean>& args) { | 417 | | - ContextifyContext* ctx = | 418 | | - Unwrap<ContextifyContext>(args.Data().As<Object>()); | | 417 | + ContextifyContext* ctx; | | 418 | + ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>()); | 419 | 419 |
| 420 | 420 | // Stil initializing | 421 | 421 | if (ctx->context_.IsEmpty()) | @@ -430,8 +430,8 @@ class ContextifyContext { | 430 | 430 |
| 431 | 431 | static void GlobalPropertyEnumeratorCallback( | 432 | 432 | const PropertyCallbackInfo<Array>& args) { | 433 | | - ContextifyContext* ctx = | 434 | | - Unwrap<ContextifyContext>(args.Data().As<Object>()); | | 433 | + ContextifyContext* ctx; | | 434 | + ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>()); | 435 | 435 |
| 436 | 436 | // Stil initializing | 437 | 437 | if (ctx->context_.IsEmpty()) | @@ -806,7 +806,8 @@ class ContextifyScript : public BaseObject { | 806 | 806 | return false; | 807 | 807 | } | 808 | 808 |
| 809 | | - ContextifyScript* wrapped_script = Unwrap<ContextifyScript>(args.Holder()); | | 809 | + ContextifyScript* wrapped_script; | | 810 | + ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder(), false); | 810 | 811 | Local<UnboundScript> unbound_script = | 811 | 812 | PersistentToLocal(env->isolate(), wrapped_script->script_); | 812 | 813 | Local<Script> script = unbound_script->BindToCurrentContext(); | |
|