| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,7 +85,6 @@ using v8::ScriptCompiler; | |||
| 85 | 85 | using v8::ScriptOrigin; | |
| 86 | 86 | using v8::String; | |
| 87 | 87 | using v8::Symbol; | |
| 88 | - using v8::Uint32; | ||
| 89 | 88 | using v8::UnboundScript; | |
| 90 | 89 | using v8::Value; | |
| 91 | 90 | ||
@@ -109,15 +108,6 @@ using v8::Value; | |||
| 109 | 108 | // For every `set` of a global property, the interceptor callback defines or | |
| 110 | 109 | // changes the property both on the sandbox and the global proxy. | |
| 111 | 110 | ||
| 112 | - namespace { | ||
| 113 | - | ||
| 114 | - // Convert an int to a V8 Name (String or Symbol). | ||
| 115 | - MaybeLocal<String> Uint32ToName(Local<Context> context, uint32_t index) { | ||
| 116 | - return Uint32::New(Isolate::GetCurrent(), index)->ToString(context); | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - } // anonymous namespace | ||
| 120 | - | ||
| 121 | 111 | ContextifyContext* ContextifyContext::New(Environment* env, | |
| 122 | 112 | Local<Object> sandbox_obj, | |
| 123 | 113 | ContextOptions* options) { | |
@@ -845,11 +835,8 @@ Intercepted ContextifyContext::IndexedPropertyQueryCallback( | |||
| 845 | 835 | return Intercepted::kNo; | |
| 846 | 836 | } | |
| 847 | 837 | ||
| 848 | - Local<String> name; | ||
| 849 | - if (Uint32ToName(ctx->context(), index).ToLocal(&name)) { | ||
| 850 | - return ContextifyContext::PropertyQueryCallback(name, args); | ||
| 851 | - } | ||
| 852 | - return Intercepted::kNo; | ||
| 838 | + Local<String> name = Uint32ToString(ctx->context(), index); | ||
| 839 | + return ContextifyContext::PropertyQueryCallback(name, args); | ||
| 853 | 840 | } | |
| 854 | 841 | ||
| 855 | 842 | // static | |
@@ -862,11 +849,8 @@ Intercepted ContextifyContext::IndexedPropertyGetterCallback( | |||
| 862 | 849 | return Intercepted::kNo; | |
| 863 | 850 | } | |
| 864 | 851 | ||
| 865 | - Local<String> name; | ||
| 866 | - if (Uint32ToName(ctx->context(), index).ToLocal(&name)) { | ||
| 867 | - return ContextifyContext::PropertyGetterCallback(name, args); | ||
| 868 | - } | ||
| 869 | - return Intercepted::kNo; | ||
| 852 | + Local<String> name = Uint32ToString(ctx->context(), index); | ||
| 853 | + return ContextifyContext::PropertyGetterCallback(name, args); | ||
| 870 | 854 | } | |
| 871 | 855 | ||
| 872 | 856 | Intercepted ContextifyContext::IndexedPropertySetterCallback( | |
@@ -880,11 +864,8 @@ Intercepted ContextifyContext::IndexedPropertySetterCallback( | |||
| 880 | 864 | return Intercepted::kNo; | |
| 881 | 865 | } | |
| 882 | 866 | ||
| 883 | - Local<String> name; | ||
| 884 | - if (Uint32ToName(ctx->context(), index).ToLocal(&name)) { | ||
| 885 | - return ContextifyContext::PropertySetterCallback(name, value, args); | ||
| 886 | - } | ||
| 887 | - return Intercepted::kNo; | ||
| 867 | + Local<String> name = Uint32ToString(ctx->context(), index); | ||
| 868 | + return ContextifyContext::PropertySetterCallback(name, value, args); | ||
| 888 | 869 | } | |
| 889 | 870 | ||
| 890 | 871 | // static | |
@@ -897,11 +878,8 @@ Intercepted ContextifyContext::IndexedPropertyDescriptorCallback( | |||
| 897 | 878 | return Intercepted::kNo; | |
| 898 | 879 | } | |
| 899 | 880 | ||
| 900 | - Local<String> name; | ||
| 901 | - if (Uint32ToName(ctx->context(), index).ToLocal(&name)) { | ||
| 902 | - return ContextifyContext::PropertyDescriptorCallback(name, args); | ||
| 903 | - } | ||
| 904 | - return Intercepted::kNo; | ||
| 881 | + Local<String> name = Uint32ToString(ctx->context(), index); | ||
| 882 | + return ContextifyContext::PropertyDescriptorCallback(name, args); | ||
| 905 | 883 | } | |
| 906 | 884 | ||
| 907 | 885 | Intercepted ContextifyContext::IndexedPropertyDefinerCallback( | |
@@ -915,11 +893,8 @@ Intercepted ContextifyContext::IndexedPropertyDefinerCallback( | |||
| 915 | 893 | return Intercepted::kNo; | |
| 916 | 894 | } | |
| 917 | 895 | ||
| 918 | - Local<String> name; | ||
| 919 | - if (Uint32ToName(ctx->context(), index).ToLocal(&name)) { | ||
| 920 | - return ContextifyContext::PropertyDefinerCallback(name, desc, args); | ||
| 921 | - } | ||
| 922 | - return Intercepted::kNo; | ||
| 896 | + Local<String> name = Uint32ToString(ctx->context(), index); | ||
| 897 | + return ContextifyContext::PropertyDefinerCallback(name, desc, args); | ||
| 923 | 898 | } | |
| 924 | 899 | ||
| 925 | 900 | // static | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,6 @@ using v8::PropertyCallbackInfo; | |||
| 41 | 41 | using v8::PropertyDescriptor; | |
| 42 | 42 | using v8::PropertyHandlerFlags; | |
| 43 | 43 | using v8::String; | |
| 44 | - using v8::Uint32; | ||
| 45 | 44 | using v8::Value; | |
| 46 | 45 | ||
| 47 | 46 | #define THROW_SQLITE_ERROR(env, r) \ | |
@@ -432,10 +431,6 @@ Maybe<void> Storage::Store(Local<Name> key, Local<Value> value) { | |||
| 432 | 431 | return JustVoid(); | |
| 433 | 432 | } | |
| 434 | 433 | ||
| 435 | - static MaybeLocal<String> Uint32ToName(Local<Context> context, uint32_t index) { | ||
| 436 | - return Uint32::New(Isolate::GetCurrent(), index)->ToString(context); | ||
| 437 | - } | ||
| 438 | - | ||
| 439 | 434 | static void Clear(const FunctionCallbackInfo<Value>& info) { | |
| 440 | 435 | Storage* storage; | |
| 441 | 436 | ASSIGN_OR_RETURN_UNWRAP(&storage, info.This()); | |
@@ -631,67 +626,37 @@ static Intercepted StorageDefiner(Local<Name> property, | |||
| 631 | 626 | static Intercepted IndexedGetter(uint32_t index, | |
| 632 | 627 | const PropertyCallbackInfo<Value>& info) { | |
| 633 | 628 | Environment* env = Environment::GetCurrent(info); | |
| 634 | - Local<Name> name; | ||
| 635 | - if (!Uint32ToName(env->context(), index).ToLocal(&name)) { | ||
| 636 | - // There was an error converting the index to a name. | ||
| 637 | - // We aren't going to return a result but let's indicate | ||
| 638 | - // that we intercepted the operation. | ||
| 639 | - return Intercepted::kYes; | ||
| 640 | - } | ||
| 629 | + Local<Name> name = Uint32ToString(env->context(), index); | ||
| 641 | 630 | return StorageGetter(name, info); | |
| 642 | 631 | } | |
| 643 | 632 | ||
| 644 | 633 | static Intercepted IndexedSetter(uint32_t index, | |
| 645 | 634 | Local<Value> value, | |
| 646 | 635 | const PropertyCallbackInfo<void>& info) { | |
| 647 | 636 | Environment* env = Environment::GetCurrent(info); | |
| 648 | - Local<Name> name; | ||
| 649 | - if (!Uint32ToName(env->context(), index).ToLocal(&name)) { | ||
| 650 | - // There was an error converting the index to a name. | ||
| 651 | - // We aren't going to return a result but let's indicate | ||
| 652 | - // that we intercepted the operation. | ||
| 653 | - return Intercepted::kYes; | ||
| 654 | - } | ||
| 637 | + Local<Name> name = Uint32ToString(env->context(), index); | ||
| 655 | 638 | return StorageSetter(name, value, info); | |
| 656 | 639 | } | |
| 657 | 640 | ||
| 658 | 641 | static Intercepted IndexedQuery(uint32_t index, | |
| 659 | 642 | const PropertyCallbackInfo<Integer>& info) { | |
| 660 | 643 | Environment* env = Environment::GetCurrent(info); | |
| 661 | - Local<Name> name; | ||
| 662 | - if (!Uint32ToName(env->context(), index).ToLocal(&name)) { | ||
| 663 | - // There was an error converting the index to a name. | ||
| 664 | - // We aren't going to return a result but let's indicate | ||
| 665 | - // that we intercepted the operation. | ||
| 666 | - return Intercepted::kYes; | ||
| 667 | - } | ||
| 644 | + Local<Name> name = Uint32ToString(env->context(), index); | ||
| 668 | 645 | return StorageQuery(name, info); | |
| 669 | 646 | } | |
| 670 | 647 | ||
| 671 | 648 | static Intercepted IndexedDeleter(uint32_t index, | |
| 672 | 649 | const PropertyCallbackInfo<Boolean>& info) { | |
| 673 | 650 | Environment* env = Environment::GetCurrent(info); | |
| 674 | - Local<Name> name; | ||
| 675 | - if (!Uint32ToName(env->context(), index).ToLocal(&name)) { | ||
| 676 | - // There was an error converting the index to a name. | ||
| 677 | - // We aren't going to return a result but let's indicate | ||
| 678 | - // that we intercepted the operation. | ||
| 679 | - return Intercepted::kYes; | ||
| 680 | - } | ||
| 651 | + Local<Name> name = Uint32ToString(env->context(), index); | ||
| 681 | 652 | return StorageDeleter(name, info); | |
| 682 | 653 | } | |
| 683 | 654 | ||
| 684 | 655 | static Intercepted IndexedDefiner(uint32_t index, | |
| 685 | 656 | const PropertyDescriptor& desc, | |
| 686 | 657 | const PropertyCallbackInfo<void>& info) { | |
| 687 | 658 | Environment* env = Environment::GetCurrent(info); | |
| 688 | - Local<Name> name; | ||
| 689 | - if (!Uint32ToName(env->context(), index).ToLocal(&name)) { | ||
| 690 | - // There was an error converting the index to a name. | ||
| 691 | - // We aren't going to return a result but let's indicate | ||
| 692 | - // that we intercepted the operation. | ||
| 693 | - return Intercepted::kYes; | ||
| 694 | - } | ||
| 659 | + Local<Name> name = Uint32ToString(env->context(), index); | ||
| 695 | 660 | return StorageDefiner(name, desc, info); | |
| 696 | 661 | } | |
| 697 | 662 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1063,6 +1063,16 @@ inline v8::MaybeLocal<v8::Object> NewDictionaryInstanceNullProto( | |||
| 1063 | 1063 | v8::Local<v8::DictionaryTemplate> tmpl, | |
| 1064 | 1064 | v8::MemorySpan<v8::MaybeLocal<v8::Value>> property_values); | |
| 1065 | 1065 | ||
| 1066 | + // Convert an uint32 to a V8 String. | ||
| 1067 | + inline v8::Local<v8::String> Uint32ToString(v8::Local<v8::Context> context, | ||
| 1068 | + uint32_t index) { | ||
| 1069 | + // V8 internally caches strings for small integers, and asserts that a | ||
| 1070 | + // non-empty string local handle is returned for `ToString`. | ||
| 1071 | + return v8::Uint32::New(v8::Isolate::GetCurrent(), index) | ||
| 1072 | + ->ToString(context) | ||
| 1073 | + .ToLocalChecked(); | ||
| 1074 | + } | ||
| 1075 | + | ||
| 1066 | 1076 | } // namespace node | |
| 1067 | 1077 | ||
| 1068 | 1078 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| Back | FazBrowse Home | New Git URL |
0 commit comments