GeezerVison is showing github.com — src: use DictionaryTemplate for permission diag channel message · nodejs/node@968bdd0
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/env-inl.h +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -842,9 +842,8 @@ void Environment::set_process_exit_handler( | 842 | 842 | #undef VP | 843 | 843 |
| 844 | 844 | #define V(Name, label, _, __) \ | 845 | | - inline v8::Local<v8::String> \ | 846 | | - IsolateData::Name##_permission_string() const { \ | 847 | | - return Name##_permission_string##_.Get(isolate_); \ | | 845 | + inline v8::Local<v8::String> IsolateData::Name##_permission_string() const { \ | | 846 | + return Name##_permission_string##_.Get(isolate_); \ | 848 | 847 | } | 849 | 848 | PERMISSIONS(V) | 850 | 849 | #undef V | @@ -879,9 +878,8 @@ void Environment::set_process_exit_handler( | 879 | 878 | #undef VP | 880 | 879 |
| 881 | 880 | #define V(Name, label, _, __) \ | 882 | | - inline v8::Local<v8::String> \ | 883 | | - Environment::Name##_permission_string() const { \ | 884 | | - return isolate_data()->Name##_permission_string(); \ | | 881 | + inline v8::Local<v8::String> Environment::Name##_permission_string() const { \ | | 882 | + return isolate_data()->Name##_permission_string(); \ | 885 | 883 | } | 886 | 884 | PERMISSIONS(V) | 887 | 885 | #undef V | |
Collapse file Copy file name to clipboardExpand all lines: src/env.cc +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -432,10 +432,9 @@ void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) { | 432 | 432 | info->primitive_values[i++]); \ | 433 | 433 | Local<String> field; \ | 434 | 434 | if (!maybe_field.ToLocal(&field)) { \ | 435 | | - fprintf(stderr, \ | 436 | | - "Failed to deserialize " #Name "_permission_string\n"); \ | | 435 | + fprintf(stderr, "Failed to deserialize " #Name "_permission_string\n"); \ | 437 | 436 | } \ | 438 | | - Name##_permission_string##_.Set(isolate_, field); \ | | 437 | + Name##_permission_string##_.Set(isolate_, field); \ | 439 | 438 | } while (0); | 440 | 439 | PERMISSIONS(V) | 441 | 440 | #undef V | |
Collapse file Copy file name to clipboardExpand all lines: src/env_properties.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 460 | 460 | V(naptr_record_template, v8::DictionaryTemplate) \ | 461 | 461 | V(object_stats_template, v8::DictionaryTemplate) \ | 462 | 462 | V(page_stats_template, v8::DictionaryTemplate) \ | | 463 | + V(permission_diagnostic_channel_message, v8::DictionaryTemplate) \ | 463 | 464 | V(pipe_constructor_template, v8::FunctionTemplate) \ | 464 | 465 | V(script_context_constructor_template, v8::FunctionTemplate) \ | 465 | 466 | V(secure_context_constructor_template, v8::FunctionTemplate) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/permission/permission.cc +34-26Lines changed: 34 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | #include "node_external_reference.h" | 9 | 9 | #include "node_file.h" | 10 | 10 |
| | 11 | +#include "v8-template.h" | 11 | 12 | #include "v8.h" | 12 | 13 |
| 13 | 14 | #include <memory> | | 17 | 18 | namespace node { | 18 | 19 |
| 19 | 20 | using v8::Context; | | 21 | +using v8::DictionaryTemplate; | 20 | 22 | using v8::FunctionCallbackInfo; | 21 | 23 | using v8::IntegrityLevel; | 22 | 24 | using v8::Local; | 23 | 25 | using v8::MaybeLocal; | 24 | 26 | using v8::Object; | | 27 | +using v8::Undefined; | 25 | 28 | using v8::Value; | 26 | 29 |
| 27 | 30 | namespace permission { | @@ -55,6 +58,20 @@ constexpr std::string_view GetDiagnosticsChannelName(PermissionScope scope) { | 55 | 58 | } | 56 | 59 | } | 57 | 60 |
| | 61 | +Local<DictionaryTemplate> GetPermissionDiagnosicsTemplate(Environment* env) { | | 62 | + auto tmpl = env->permission_diagnostic_channel_message(); | | 63 | + if (tmpl.IsEmpty()) { | | 64 | + static constexpr std::string_view names[] = { | | 65 | + "permission", | | 66 | + "resource", | | 67 | + "drop", | | 68 | + }; | | 69 | + tmpl = DictionaryTemplate::New(env->isolate(), names); | | 70 | + env->set_permission_diagnostic_channel_message(tmpl); | | 71 | + } | | 72 | + return tmpl; | | 73 | +} | | 74 | + | 58 | 75 | // permission.drop('fs.read', '/tmp/') | 59 | 76 | // permission.drop('child') | 60 | 77 | static void Drop(const FunctionCallbackInfo<Value>& args) { | @@ -259,17 +276,14 @@ bool Permission::is_scope_granted(Environment* env, | 259 | 276 | v8::Isolate* isolate = env->isolate(); | 260 | 277 | v8::HandleScope handle_scope(isolate); | 261 | 278 | v8::Local<v8::Context> context = env->context(); | 262 | | - v8::Local<v8::Object> msg = | 263 | | - v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0); | 264 | | - msg->Set(context, | 265 | | - env->permission_string(), | 266 | | - PermissionToString(env, permission)) | 267 | | - .Check(); | 268 | | - msg->Set(context, | 269 | | - env->resource_string(), | 270 | | - ToV8Value(context, res).ToLocalChecked()) | 271 | | - .Check(); | 272 | | - ch->Publish(env, msg); | | 279 | + v8::MaybeLocal<v8::Value> values[] = { | | 280 | + PermissionToString(env, permission), | | 281 | + ToV8Value(context, res), | | 282 | + Undefined(isolate), | | 283 | + }; | | 284 | + ch->Publish( | | 285 | + env, | | 286 | + GetPermissionDiagnosicsTemplate(env)->NewInstance(context, values)); | 273 | 287 | publishing_ = false; | 274 | 288 | } | 275 | 289 | } | @@ -324,21 +338,15 @@ void Permission::Drop(Environment* env, | 324 | 338 | v8::Isolate* isolate = env->isolate(); | 325 | 339 | v8::HandleScope handle_scope(isolate); | 326 | 340 | v8::Local<v8::Context> context = env->context(); | 327 | | - v8::Local<v8::Object> msg = | 328 | | - v8::Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0); | 329 | | - msg->Set(context, | 330 | | - env->permission_string(), | 331 | | - PermissionToString(env, scope)) | 332 | | - .Check(); | 333 | | - msg->Set(context, | 334 | | - env->resource_string(), | 335 | | - ToV8Value(context, param).ToLocalChecked()) | 336 | | - .Check(); | 337 | | - msg->Set(context, | 338 | | - FIXED_ONE_BYTE_STRING(isolate, "drop"), | 339 | | - v8::Boolean::New(isolate, true)) | 340 | | - .Check(); | 341 | | - ch->Publish(env, msg); | | 341 | + | | 342 | + v8::MaybeLocal<v8::Value> values[] = { | | 343 | + PermissionToString(env, scope), | | 344 | + ToV8Value(context, param), | | 345 | + v8::True(isolate), | | 346 | + }; | | 347 | + ch->Publish( | | 348 | + env, | | 349 | + GetPermissionDiagnosicsTemplate(env)->NewInstance(context, values)); | 342 | 350 | publishing_ = false; | 343 | 351 | } | 344 | 352 | } | |
|