GeezerVison is showing github.com — src: avoid prototype access in binding templates · nodejs/node@b25e704
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/async_wrap.cc +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -353,9 +353,8 @@ Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate( | 353 | 353 | } | 354 | 354 |
| 355 | 355 | void AsyncWrap::CreatePerIsolateProperties(IsolateData* isolate_data, | 356 | | - Local<FunctionTemplate> ctor) { | | 356 | + Local<ObjectTemplate> target) { | 357 | 357 | Isolate* isolate = isolate_data->isolate(); | 358 | | - Local<ObjectTemplate> target = ctor->InstanceTemplate(); | 359 | 358 |
| 360 | 359 | SetMethod(isolate, target, "setupHooks", SetupHooks); | 361 | 360 | SetMethod(isolate, target, "setCallbackTrampoline", SetCallbackTrampoline); | |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,8 +149,8 @@ class AsyncWrap : public BaseObject { | 149 | 149 | v8::Local<v8::Value> unused, | 150 | 150 | v8::Local<v8::Context> context, | 151 | 151 | void* priv); | 152 | | - static void CreatePerIsolateProperties( | 153 | | - IsolateData* isolate_data, v8::Local<v8::FunctionTemplate> target); | | 152 | + static void CreatePerIsolateProperties(IsolateData* isolate_data, | | 153 | + v8::Local<v8::ObjectTemplate> target); | 154 | 154 |
| 155 | 155 | static void GetAsyncId(const v8::FunctionCallbackInfo<v8::Value>& args); | 156 | 156 | static void PushAsyncContext(const v8::FunctionCallbackInfo<v8::Value>& args); | |
Collapse file Copy file name to clipboardExpand all lines: src/encoding_binding.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,6 @@ using v8::ArrayBuffer; | 16 | 16 | using v8::BackingStore; | 17 | 17 | using v8::Context; | 18 | 18 | using v8::FunctionCallbackInfo; | 19 | | -using v8::FunctionTemplate; | 20 | 19 | using v8::Isolate; | 21 | 20 | using v8::Local; | 22 | 21 | using v8::MaybeLocal; | @@ -219,9 +218,8 @@ void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) { | 219 | 218 | } | 220 | 219 |
| 221 | 220 | void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | 222 | | - Local<FunctionTemplate> ctor) { | | 221 | + Local<ObjectTemplate> target) { | 223 | 222 | Isolate* isolate = isolate_data->isolate(); | 224 | | - Local<ObjectTemplate> target = ctor->InstanceTemplate(); | 225 | 223 | SetMethod(isolate, target, "encodeInto", EncodeInto); | 226 | 224 | SetMethodNoSideEffect(isolate, target, "encodeUtf8String", EncodeUtf8String); | 227 | 225 | SetMethodNoSideEffect(isolate, target, "decodeUTF8", DecodeUTF8); | |
Collapse file Copy file name to clipboardExpand all lines: src/encoding_binding.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,7 @@ class BindingData : public SnapshotableObject { | 36 | 36 | static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args); | 37 | 37 |
| 38 | 38 | static void CreatePerIsolateProperties(IsolateData* isolate_data, | 39 | | - v8::Local<v8::FunctionTemplate> ctor); | | 39 | + v8::Local<v8::ObjectTemplate> target); | 40 | 40 | static void CreatePerContextProperties(v8::Local<v8::Object> target, | 41 | 41 | v8::Local<v8::Value> unused, | 42 | 42 | v8::Local<v8::Context> context, | |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -807,7 +807,7 @@ void Environment::set_process_exit_handler( | 807 | 807 | #undef VY | 808 | 808 | #undef VP | 809 | 809 |
| 810 | | -#define VM(PropertyName) V(PropertyName##_binding, v8::FunctionTemplate) | | 810 | +#define VM(PropertyName) V(PropertyName##_binding_template, v8::ObjectTemplate) | 811 | 811 | #define V(PropertyName, TypeName) \ | 812 | 812 | inline v8::Local<TypeName> IsolateData::PropertyName() const { \ | 813 | 813 | return PropertyName##_.Get(isolate_); \ | |
Collapse file Copy file name to clipboardExpand all lines: src/env.cc +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ using v8::Context; | 38 | 38 | using v8::EmbedderGraph; | 39 | 39 | using v8::EscapableHandleScope; | 40 | 40 | using v8::Function; | 41 | | -using v8::FunctionTemplate; | 42 | 41 | using v8::HandleScope; | 43 | 42 | using v8::HeapProfiler; | 44 | 43 | using v8::HeapSpaceStatistics; | @@ -49,6 +48,7 @@ using v8::MaybeLocal; | 49 | 48 | using v8::NewStringType; | 50 | 49 | using v8::Number; | 51 | 50 | using v8::Object; | | 51 | +using v8::ObjectTemplate; | 52 | 52 | using v8::Private; | 53 | 53 | using v8::Script; | 54 | 54 | using v8::SnapshotCreator; | @@ -326,7 +326,7 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) { | 326 | 326 | info.primitive_values.push_back(creator->AddData(async_wrap_provider(i))); | 327 | 327 |
| 328 | 328 | uint32_t id = 0; | 329 | | -#define VM(PropertyName) V(PropertyName##_binding, FunctionTemplate) | | 329 | +#define VM(PropertyName) V(PropertyName##_binding_template, ObjectTemplate) | 330 | 330 | #define V(PropertyName, TypeName) \ | 331 | 331 | do { \ | 332 | 332 | Local<TypeName> field = PropertyName(); \ | @@ -390,7 +390,7 @@ void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) { | 390 | 390 | const std::vector<PropInfo>& values = info->template_values; | 391 | 391 | i = 0; // index to the array | 392 | 392 | uint32_t id = 0; | 393 | | -#define VM(PropertyName) V(PropertyName##_binding, FunctionTemplate) | | 393 | +#define VM(PropertyName) V(PropertyName##_binding_template, ObjectTemplate) | 394 | 394 | #define V(PropertyName, TypeName) \ | 395 | 395 | do { \ | 396 | 396 | if (values.size() > i && id == values[i].id) { \ | @@ -491,10 +491,9 @@ void IsolateData::CreateProperties() { | 491 | 491 | NODE_ASYNC_PROVIDER_TYPES(V) | 492 | 492 | #undef V | 493 | 493 |
| 494 | | - Local<FunctionTemplate> templ = FunctionTemplate::New(isolate()); | 495 | | - templ->InstanceTemplate()->SetInternalFieldCount( | 496 | | - BaseObject::kInternalFieldCount); | 497 | | - set_binding_data_ctor_template(templ); | | 494 | + Local<ObjectTemplate> templ = ObjectTemplate::New(isolate()); | | 495 | + templ->SetInternalFieldCount(BaseObject::kInternalFieldCount); | | 496 | + set_binding_data_default_template(templ); | 498 | 497 | binding::CreateInternalBindingTemplates(this); | 499 | 498 |
| 500 | 499 | contextify::ContextifyContext::InitializeGlobalTemplates(this); | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -166,7 +166,7 @@ class NODE_EXTERN_PRIVATE IsolateData : public MemoryRetainer { | 166 | 166 | #undef VS | 167 | 167 | #undef VP | 168 | 168 |
| 169 | | -#define VM(PropertyName) V(PropertyName##_binding, v8::FunctionTemplate) | | 169 | +#define VM(PropertyName) V(PropertyName##_binding_template, v8::ObjectTemplate) | 170 | 170 | #define V(PropertyName, TypeName) \ | 171 | 171 | inline v8::Local<TypeName> PropertyName() const; \ | 172 | 172 | inline void set_##PropertyName(v8::Local<TypeName> value); | @@ -194,7 +194,7 @@ class NODE_EXTERN_PRIVATE IsolateData : public MemoryRetainer { | 194 | 194 | #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | 195 | 195 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | 196 | 196 | #define VR(PropertyName, TypeName) V(v8::Private, per_realm_##PropertyName) | 197 | | -#define VM(PropertyName) V(v8::FunctionTemplate, PropertyName##_binding) | | 197 | +#define VM(PropertyName) V(v8::ObjectTemplate, PropertyName##_binding_template) | 198 | 198 | #define VT(PropertyName, TypeName) V(TypeName, PropertyName) | 199 | 199 | #define V(TypeName, PropertyName) \ | 200 | 200 | v8::Eternal<TypeName> PropertyName ## _; | |
Collapse file Copy file name to clipboardExpand all lines: src/env_properties.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 331 | 331 | #define PER_ISOLATE_TEMPLATE_PROPERTIES(V) \ | 332 | 332 | V(async_wrap_ctor_template, v8::FunctionTemplate) \ | 333 | 333 | V(async_wrap_object_ctor_template, v8::FunctionTemplate) \ | 334 | | - V(binding_data_ctor_template, v8::FunctionTemplate) \ | | 334 | + V(binding_data_default_template, v8::ObjectTemplate) \ | 335 | 335 | V(blob_constructor_template, v8::FunctionTemplate) \ | 336 | 336 | V(blob_reader_constructor_template, v8::FunctionTemplate) \ | 337 | 337 | V(blocklist_constructor_template, v8::FunctionTemplate) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_binding.cc +12-14Lines changed: 12 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,7 +101,7 @@ NODE_BUILTIN_BINDINGS(V) | 101 | 101 |
| 102 | 102 | #define V(modname) \ | 103 | 103 | void _register_isolate_##modname(node::IsolateData* isolate_data, \ | 104 | | - v8::Local<v8::FunctionTemplate> target); | | 104 | + v8::Local<v8::ObjectTemplate> target); | 105 | 105 | NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) | 106 | 106 | #undef V | 107 | 107 |
| @@ -235,11 +235,11 @@ using v8::Context; | 235 | 235 | using v8::EscapableHandleScope; | 236 | 236 | using v8::Exception; | 237 | 237 | using v8::FunctionCallbackInfo; | 238 | | -using v8::FunctionTemplate; | 239 | 238 | using v8::HandleScope; | 240 | 239 | using v8::Isolate; | 241 | 240 | using v8::Local; | 242 | 241 | using v8::Object; | | 242 | +using v8::ObjectTemplate; | 243 | 243 | using v8::String; | 244 | 244 | using v8::Value; | 245 | 245 |
| @@ -572,12 +572,11 @@ inline struct node_module* FindModule(struct node_module* list, | 572 | 572 | void CreateInternalBindingTemplates(IsolateData* isolate_data) { | 573 | 573 | #define V(modname) \ | 574 | 574 | do { \ | 575 | | - Local<FunctionTemplate> templ = \ | 576 | | - FunctionTemplate::New(isolate_data->isolate()); \ | 577 | | - templ->InstanceTemplate()->SetInternalFieldCount( \ | 578 | | - BaseObject::kInternalFieldCount); \ | | 575 | + Local<ObjectTemplate> templ = \ | | 576 | + ObjectTemplate::New(isolate_data->isolate()); \ | | 577 | + templ->SetInternalFieldCount(BaseObject::kInternalFieldCount); \ | 579 | 578 | _register_isolate_##modname(isolate_data, templ); \ | 580 | | - isolate_data->set_##modname##_binding(templ); \ | | 579 | + isolate_data->set_##modname##_binding_template(templ); \ | 581 | 580 | } while (0); | 582 | 581 | NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) | 583 | 582 | #undef V | @@ -586,21 +585,20 @@ void CreateInternalBindingTemplates(IsolateData* isolate_data) { | 586 | 585 | static Local<Object> GetInternalBindingExportObject(IsolateData* isolate_data, | 587 | 586 | const char* mod_name, | 588 | 587 | Local<Context> context) { | 589 | | - Local<FunctionTemplate> ctor; | | 588 | + Local<ObjectTemplate> templ; | | 589 | + | 590 | 590 | #define V(name) \ | 591 | 591 | if (strcmp(mod_name, #name) == 0) { \ | 592 | | - ctor = isolate_data->name##_binding(); \ | | 592 | + templ = isolate_data->name##_binding_template(); \ | 593 | 593 | } else // NOLINT(readability/braces) | 594 | 594 | NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) | 595 | 595 | #undef V | 596 | 596 | { | 597 | | - ctor = isolate_data->binding_data_ctor_template(); | | 597 | + // Default template. | | 598 | + templ = isolate_data->binding_data_default_template(); | 598 | 599 | } | 599 | 600 |
| 600 | | - Local<Object> obj = ctor->GetFunction(context) | 601 | | - .ToLocalChecked() | 602 | | - ->NewInstance(context) | 603 | | - .ToLocalChecked(); | | 601 | + Local<Object> obj = templ->NewInstance(context).ToLocalChecked(); | 604 | 602 | return obj; | 605 | 603 | } | 606 | 604 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_binding.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,7 +84,7 @@ namespace node { | 84 | 84 | // list. | 85 | 85 | #define NODE_BINDING_PER_ISOLATE_INIT(modname, per_isolate_func) \ | 86 | 86 | void _register_isolate_##modname(node::IsolateData* isolate_data, \ | 87 | | - v8::Local<v8::FunctionTemplate> target) { \ | | 87 | + v8::Local<v8::ObjectTemplate> target) { \ | 88 | 88 | per_isolate_func(isolate_data, target); \ | 89 | 89 | } | 90 | 90 |
| |
|