| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7ddbf94 commit 974b7b6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,25 +24,27 @@ void CreateEnvProxyTemplate(IsolateData* isolate_data); | |||
| 24 | 24 | void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 25 | 25 | ||
| 26 | 26 | v8::MaybeLocal<v8::Value> ProcessEmit(Environment* env, | |
| 27 | - const char* event, | ||
| 27 | + std::string_view event, | ||
| 28 | 28 | v8::Local<v8::Value> message); | |
| 29 | 29 | ||
| 30 | 30 | v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |
| 31 | - const char* warning, | ||
| 32 | - const char* type = nullptr, | ||
| 33 | - const char* code = nullptr); | ||
| 31 | + std::string_view warning, | ||
| 32 | + std::string_view type = "", | ||
| 33 | + std::string_view code = ""); | ||
| 34 | 34 | ||
| 35 | 35 | template <typename... Args> | |
| 36 | 36 | inline v8::Maybe<bool> ProcessEmitWarning(Environment* env, | |
| 37 | 37 | const char* fmt, | |
| 38 | 38 | Args&&... args); | |
| 39 | 39 | ||
| 40 | - v8::Maybe<bool> ProcessEmitWarningSync(Environment* env, const char* message); | ||
| 40 | + v8::Maybe<bool> ProcessEmitWarningSync(Environment* env, | ||
| 41 | + std::string_view message); | ||
| 41 | 42 | v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | |
| 42 | - const char* warning); | ||
| 43 | - v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | ||
| 44 | - const char* warning, | ||
| 45 | - const char* deprecation_code); | ||
| 43 | + const std::string& warning); | ||
| 44 | + v8::Maybe<bool> ProcessEmitDeprecationWarning( | ||
| 45 | + Environment* env, | ||
| 46 | + const std::string& warning, | ||
| 47 | + std::string_view deprecation_code); | ||
| 46 | 48 | ||
| 47 | 49 | v8::MaybeLocal<v8::Object> CreateProcessObject(Realm* env); | |
| 48 | 50 | void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,10 +18,11 @@ using v8::Object; | |||
| 18 | 18 | using v8::String; | |
| 19 | 19 | using v8::Value; | |
| 20 | 20 | ||
| 21 | - Maybe<bool> ProcessEmitWarningSync(Environment* env, const char* message) { | ||
| 21 | + Maybe<bool> ProcessEmitWarningSync(Environment* env, std::string_view message) { | ||
| 22 | 22 | Isolate* isolate = env->isolate(); | |
| 23 | 23 | Local<Context> context = env->context(); | |
| 24 | - Local<String> message_string = OneByteString(isolate, message); | ||
| 24 | + Local<String> message_string = | ||
| 25 | + OneByteString(isolate, message.data(), message.size()); | ||
| 25 | 26 | ||
| 26 | 27 | Local<Value> argv[] = {message_string}; | |
| 27 | 28 | Local<Function> emit_function = env->process_emit_warning_sync(); | |
@@ -37,24 +38,27 @@ Maybe<bool> ProcessEmitWarningSync(Environment* env, const char* message) { | |||
| 37 | 38 | } | |
| 38 | 39 | ||
| 39 | 40 | MaybeLocal<Value> ProcessEmit(Environment* env, | |
| 40 | - const char* event, | ||
| 41 | + std::string_view event, | ||
| 41 | 42 | Local<Value> message) { | |
| 42 | 43 | Isolate* isolate = env->isolate(); | |
| 43 | 44 | ||
| 44 | - Local<String> event_string; | ||
| 45 | - if (!String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(event)) | ||
| 46 | - .ToLocal(&event_string)) return MaybeLocal<Value>(); | ||
| 45 | + Local<Value> event_string; | ||
| 46 | + if (!ToV8Value(env->context(), event).ToLocal(&event_string)) { | ||
| 47 | + return MaybeLocal<Value>(); | ||
| 48 | + } | ||
| 47 | 49 | ||
| 48 | 50 | Local<Object> process = env->process_object(); | |
| 49 | 51 | Local<Value> argv[] = {event_string, message}; | |
| 50 | 52 | return MakeCallback(isolate, process, "emit", arraysize(argv), argv, {0, 0}); | |
| 51 | 53 | } | |
| 52 | 54 | ||
| 53 | 55 | Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |
| 54 | - const char* warning, | ||
| 55 | - const char* type, | ||
| 56 | - const char* code) { | ||
| 57 | - if (!env->can_call_into_js()) return Just(false); | ||
| 56 | + std::string_view warning, | ||
| 57 | + std::string_view type, | ||
| 58 | + std::string_view code) { | ||
| 59 | + if (!env->can_call_into_js()) { | ||
| 60 | + return Just(false); | ||
| 61 | + } | ||
| 58 | 62 | ||
| 59 | 63 | HandleScope handle_scope(env->isolate()); | |
| 60 | 64 | Context::Scope context_scope(env->context()); | |
@@ -73,19 +77,16 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |||
| 73 | 77 | ||
| 74 | 78 | // The caller has to be able to handle a failure anyway, so we might as well | |
| 75 | 79 | // do proper error checking for string creation. | |
| 76 | - if (!String::NewFromUtf8(env->isolate(), warning).ToLocal(&args[argc++])) | ||
| 80 | + if (!ToV8Value(env->context(), warning).ToLocal(&args[argc++])) { | ||
| 77 | 81 | return Nothing<bool>(); | |
| 82 | + } | ||
| 78 | 83 | ||
| 79 | - if (type != nullptr) { | ||
| 80 | - if (!String::NewFromOneByte(env->isolate(), | ||
| 81 | - reinterpret_cast<const uint8_t*>(type)) | ||
| 82 | - .ToLocal(&args[argc++])) { | ||
| 84 | + if (!type.empty()) { | ||
| 85 | + if (!ToV8Value(env->context(), type).ToLocal(&args[argc++])) { | ||
| 83 | 86 | return Nothing<bool>(); | |
| 84 | 87 | } | |
| 85 | - if (code != nullptr && | ||
| 86 | - !String::NewFromOneByte(env->isolate(), | ||
| 87 | - reinterpret_cast<const uint8_t*>(code)) | ||
| 88 | - .ToLocal(&args[argc++])) { | ||
| 88 | + if (!code.empty() && | ||
| 89 | + !ToV8Value(env->context(), code).ToLocal(&args[argc++])) { | ||
| 89 | 90 | return Nothing<bool>(); | |
| 90 | 91 | } | |
| 91 | 92 | } | |
@@ -100,13 +101,11 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |||
| 100 | 101 | return Just(true); | |
| 101 | 102 | } | |
| 102 | 103 | ||
| 103 | - | ||
| 104 | 104 | std::set<std::string> experimental_warnings; | |
| 105 | 105 | ||
| 106 | 106 | Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | |
| 107 | - const char* warning) { | ||
| 108 | - if (experimental_warnings.find(warning) != experimental_warnings.end()) | ||
| 109 | - return Nothing<bool>(); | ||
| 107 | + const std::string& warning) { | ||
| 108 | + if (experimental_warnings.contains(warning)) return Nothing<bool>(); | ||
| 110 | 109 | ||
| 111 | 110 | experimental_warnings.insert(warning); | |
| 112 | 111 | std::string message(warning); | |
@@ -115,8 +114,8 @@ Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | |||
| 115 | 114 | } | |
| 116 | 115 | ||
| 117 | 116 | Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |
| 118 | - const char* warning, | ||
| 119 | - const char* deprecation_code) { | ||
| 117 | + const std::string& warning, | ||
| 118 | + std::string_view deprecation_code) { | ||
| 120 | 119 | return ProcessEmitWarningGeneric( | |
| 121 | 120 | env, warning, "DeprecationWarning", deprecation_code); | |
| 122 | 121 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments