| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 289d0bf commit f1a8108
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -157,11 +157,11 @@ The context-aware addon can be structured to avoid global static data by | |||
| 157 | 157 | performing the following steps: | |
| 158 | 158 | * Define a class which will hold per-addon-instance data and which has a static | |
| 159 | 159 | member of the form | |
| 160 | - ```C++ | ||
| 161 | - static void DeleteInstance(void* data) { | ||
| 162 | - // Cast `data` to an instance of the class and delete it. | ||
| 163 | - } | ||
| 164 | - ``` | ||
| 160 | + ```cpp | ||
| 161 | + static void DeleteInstance(void* data) { | ||
| 162 | + // Cast `data` to an instance of the class and delete it. | ||
| 163 | + } | ||
| 164 | + ``` | ||
| 165 | 165 | * Heap-allocate an instance of this class in the addon initializer. This can be | |
| 166 | 166 | accomplished using the `new` keyword. | |
| 167 | 167 | * Call `node::AddEnvironmentCleanupHook()`, passing it the above-created | |
@@ -245,7 +245,7 @@ In order to support [`Worker`][] threads, addons need to clean up any resources | |||
| 245 | 245 | they may have allocated when such a thread exists. This can be achieved through | |
| 246 | 246 | the usage of the `AddEnvironmentCleanupHook()` function: | |
| 247 | 247 | ||
| 248 | - ```c++ | ||
| 248 | + ```cpp | ||
| 249 | 249 | void AddEnvironmentCleanupHook(v8::Isolate* isolate, | |
| 250 | 250 | void (*fun)(void* arg), | |
| 251 | 251 | void* arg); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,12 +45,12 @@ following `node-addon-api` code. The first section shows the | |||
| 45 | 45 | `node-addon-api` code and the second section shows what actually gets | |
| 46 | 46 | used in the addon. | |
| 47 | 47 | ||
| 48 | - ```C++ | ||
| 48 | + ```cpp | ||
| 49 | 49 | Object obj = Object::New(env); | |
| 50 | 50 | obj["foo"] = String::New(env, "bar"); | |
| 51 | 51 | ``` | |
| 52 | 52 | ||
| 53 | - ```C++ | ||
| 53 | + ```cpp | ||
| 54 | 54 | napi_status status; | |
| 55 | 55 | napi_value object, string; | |
| 56 | 56 | status = napi_create_object(env, &object); | |
@@ -87,7 +87,7 @@ versions: | |||
| 87 | 87 | ||
| 88 | 88 | * the Node.js C++ APIs available via any of | |
| 89 | 89 | ||
| 90 | - ```C++ | ||
| 90 | + ```cpp | ||
| 91 | 91 | #include <node.h> | |
| 92 | 92 | #include <node_buffer.h> | |
| 93 | 93 | #include <node_version.h> | |
@@ -96,13 +96,13 @@ versions: | |||
| 96 | 96 | ||
| 97 | 97 | * the libuv APIs which are also included with Node.js and available via | |
| 98 | 98 | ||
| 99 | - ```C++ | ||
| 99 | + ```cpp | ||
| 100 | 100 | #include <uv.h> | |
| 101 | 101 | ``` | |
| 102 | 102 | ||
| 103 | 103 | * the V8 API available via | |
| 104 | 104 | ||
| 105 | - ```C++ | ||
| 105 | + ```cpp | ||
| 106 | 106 | #include <v8.h> | |
| 107 | 107 | ``` | |
| 108 | 108 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,7 @@ Comments should also start with uppercase and finish with a dot. | |||
| 67 | 67 | ||
| 68 | 68 | Examples: | |
| 69 | 69 | ||
| 70 | - ```c++ | ||
| 70 | + ```cpp | ||
| 71 | 71 | // A single-line comment. | |
| 72 | 72 | ||
| 73 | 73 | // Multi-line comments | |
@@ -82,14 +82,14 @@ comments. | |||
| 82 | 82 | ||
| 83 | 83 | ### 2 spaces of indentation for blocks or bodies of conditionals | |
| 84 | 84 | ||
| 85 | - ```c++ | ||
| 85 | + ```cpp | ||
| 86 | 86 | if (foo) | |
| 87 | 87 | bar(); | |
| 88 | 88 | ``` | |
| 89 | 89 | ||
| 90 | 90 | or | |
| 91 | 91 | ||
| 92 | - ```c++ | ||
| 92 | + ```cpp | ||
| 93 | 93 | if (foo) { | |
| 94 | 94 | bar(); | |
| 95 | 95 | baz(); | |
@@ -102,7 +102,7 @@ Braces are optional if the statement body only has one line. | |||
| 102 | 102 | ||
| 103 | 103 | ### 4 spaces of indentation for statement continuations | |
| 104 | 104 | ||
| 105 | - ```c++ | ||
| 105 | + ```cpp | ||
| 106 | 106 | VeryLongTypeName very_long_result = SomeValueWithAVeryLongName + | |
| 107 | 107 | SomeOtherValueWithAVeryLongName; | |
| 108 | 108 | ``` | |
@@ -111,15 +111,15 @@ Operators are before the line break in these cases. | |||
| 111 | 111 | ||
| 112 | 112 | ### Align function arguments vertically | |
| 113 | 113 | ||
| 114 | - ```c++ | ||
| 114 | + ```cpp | ||
| 115 | 115 | void FunctionWithAVeryLongName(int parameter_with_a_very_long_name, | |
| 116 | 116 | double other_parameter_with_a_very_long_name, | |
| 117 | 117 | ...); | |
| 118 | 118 | ``` | |
| 119 | 119 | ||
| 120 | 120 | If that doesn’t work, break after the `(` and use 4 spaces of indentation: | |
| 121 | 121 | ||
| 122 | - ```c++ | ||
| 122 | + ```cpp | ||
| 123 | 123 | void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt( | |
| 124 | 124 | int okay_there_is_no_space_left_in_the_previous_line, | |
| 125 | 125 | ...); | |
@@ -129,7 +129,7 @@ void FunctionWithAReallyReallyReallyLongNameSeriouslyStopIt( | |||
| 129 | 129 | ||
| 130 | 130 | Long initialization lists are formatted like this: | |
| 131 | 131 | ||
| 132 | - ```c++ | ||
| 132 | + ```cpp | ||
| 133 | 133 | HandleWrap::HandleWrap(Environment* env, | |
| 134 | 134 | Local<Object> object, | |
| 135 | 135 | uv_handle_t* handle, | |
@@ -144,7 +144,7 @@ HandleWrap::HandleWrap(Environment* env, | |||
| 144 | 144 | Exceptions are simple getters/setters, which are named `property_name()` and | |
| 145 | 145 | `set_property_name()`, respectively. | |
| 146 | 146 | ||
| 147 | - ```c++ | ||
| 147 | + ```cpp | ||
| 148 | 148 | class FooBar { | |
| 149 | 149 | public: | |
| 150 | 150 | void DoSomething(); | |
@@ -157,15 +157,15 @@ class FooBar { | |||
| 157 | 157 | ||
| 158 | 158 | ### `snake_case` for local variables and parameters | |
| 159 | 159 | ||
| 160 | - ```c++ | ||
| 160 | + ```cpp | ||
| 161 | 161 | int FunctionThatDoesSomething(const char* important_string) { | |
| 162 | 162 | const char* pointer_into_string = important_string; | |
| 163 | 163 | } | |
| 164 | 164 | ``` | |
| 165 | 165 | ||
| 166 | 166 | ### `snake_case_` for private class fields | |
| 167 | 167 | ||
| 168 | - ```c++ | ||
| 168 | + ```cpp | ||
| 169 | 169 | class Foo { | |
| 170 | 170 | private: | |
| 171 | 171 | int counter_ = 0; | |
@@ -176,15 +176,15 @@ class Foo { | |||
| 176 | 176 | ||
| 177 | 177 | For plain C-like structs snake_case can be used. | |
| 178 | 178 | ||
| 179 | - ```c++ | ||
| 179 | + ```cpp | ||
| 180 | 180 | struct foo_bar { | |
| 181 | 181 | int name; | |
| 182 | 182 | } | |
| 183 | 183 | ``` | |
| 184 | 184 | ||
| 185 | 185 | ### Space after `template` | |
| 186 | 186 | ||
| 187 | - ```c++ | ||
| 187 | + ```cpp | ||
| 188 | 188 | template <typename T> | |
| 189 | 189 | class FancyContainer { | |
| 190 | 190 | ... | |
@@ -232,7 +232,7 @@ Using non-const references often obscures which values are changed by an | |||
| 232 | 232 | assignment. Consider using a pointer instead, which requires more explicit | |
| 233 | 233 | syntax to indicate that modifications take place. | |
| 234 | 234 | ||
| 235 | - ```c++ | ||
| 235 | + ```cpp | ||
| 236 | 236 | class ExampleClass { | |
| 237 | 237 | public: | |
| 238 | 238 | explicit ExampleClass(OtherClass* other_ptr) : pointer_to_other_(other_ptr) {} | |
@@ -269,7 +269,7 @@ When working with typed arrays that involve direct data modification | |||
| 269 | 269 | from C++, use an `AliasedBuffer` when possible. The API abstraction and | |
| 270 | 270 | the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][]. | |
| 271 | 271 | ||
| 272 | - ```c++ | ||
| 272 | + ```cpp | ||
| 273 | 273 | // Create an AliasedBuffer. | |
| 274 | 274 | AliasedBuffer<uint32_t, v8::Uint32Array> data; | |
| 275 | 275 | ... | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,7 +103,7 @@ example leak based on the "Hello world" addon from | |||
| 103 | 103 | In this example, a loop which allocates ~1MB of memory and never frees it | |
| 104 | 104 | has been added: | |
| 105 | 105 | ||
| 106 | - ```C++ | ||
| 106 | + ```cpp | ||
| 107 | 107 | void* malloc_holder = nullptr; | |
| 108 | 108 | napi_value Method(napi_env env, napi_callback_info info) { | |
| 109 | 109 | napi_status status; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ For example, if we want to add a constant with the offset for | |||
| 35 | 35 | `sizeof(req_)` depends on the type of T, which means the class definition should | |
| 36 | 36 | be like this: | |
| 37 | 37 | ||
| 38 | - ```c++ | ||
| 38 | + ```cpp | ||
| 39 | 39 | template <typename T> | |
| 40 | 40 | class ReqWrap : public AsyncWrap { | |
| 41 | 41 | private: | |
@@ -49,7 +49,7 @@ class ReqWrap : public AsyncWrap { | |||
| 49 | 49 | ||
| 50 | 50 | instead of: | |
| 51 | 51 | ||
| 52 | - ```c++ | ||
| 52 | + ```cpp | ||
| 53 | 53 | template <typename T> | |
| 54 | 54 | class ReqWrap : public AsyncWrap { | |
| 55 | 55 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -356,7 +356,7 @@ The unit test should be placed in `test/cctest` and be named with the prefix | |||
| 356 | 356 | `test` followed by the name of unit being tested. For example, the code below | |
| 357 | 357 | would be placed in `test/cctest/test_env.cc`: | |
| 358 | 358 | ||
| 359 | - ```c++ | ||
| 359 | + ```cpp | ||
| 360 | 360 | #include "gtest/gtest.h" | |
| 361 | 361 | #include "node_test_fixture.h" | |
| 362 | 362 | #include "env.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,7 +137,7 @@ function getFoo(obj) { | |||
| 137 | 137 | } | |
| 138 | 138 | ``` | |
| 139 | 139 | ||
| 140 | - ```c++ | ||
| 140 | + ```cpp | ||
| 141 | 141 | v8::Local<v8::Value> GetFoo(v8::Local<v8::Context> context, | |
| 142 | 142 | v8::Local<v8::Object> obj) { | |
| 143 | 143 | v8::Isolate* isolate = context->GetIsolate(); | |
@@ -168,7 +168,7 @@ See [exception handling][] for more information about the usage of `.To()`, | |||
| 168 | 168 | If it is known that a `Local<Value>` refers to a more specific type, it can | |
| 169 | 169 | be cast to that type using `.As<...>()`: | |
| 170 | 170 | ||
| 171 | - ```c++ | ||
| 171 | + ```cpp | ||
| 172 | 172 | v8::Local<v8::Value> some_value; | |
| 173 | 173 | // CHECK() is a Node.js utilitity that works similar to assert(). | |
| 174 | 174 | CHECK(some_value->IsUint8Array()); | |
@@ -201,7 +201,7 @@ alive even if no other objects refer to them. Weak global handles do not do | |||
| 201 | 201 | that, and instead optionally call a callback when the object they refer to | |
| 202 | 202 | is garbage-collected. | |
| 203 | 203 | ||
| 204 | - ```c++ | ||
| 204 | + ```cpp | ||
| 205 | 205 | v8::Global<v8::Object> reference; | |
| 206 | 206 | ||
| 207 | 207 | void StoreReference(v8::Isolate* isolate, v8::Local<v8::Object> obj) { | |
@@ -329,7 +329,7 @@ The platform can be accessed through `isolate_data->platform()` given an | |||
| 329 | 329 | C++ functions exposed to JS follow a specific signature. The following example | |
| 330 | 330 | is from `node_util.cc`: | |
| 331 | 331 | ||
| 332 | - ```c++ | ||
| 332 | + ```cpp | ||
| 333 | 333 | void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) { | |
| 334 | 334 | CHECK(args[0]->IsArrayBufferView()); | |
| 335 | 335 | args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer()); | |
@@ -351,7 +351,7 @@ floating-point number or a `Local<Value>` to set the return value. | |||
| 351 | 351 | Node.js provides various helpers for building JS classes in C++ and/or attaching | |
| 352 | 352 | C++ functions to the exports of a built-in module: | |
| 353 | 353 | ||
| 354 | - ```c++ | ||
| 354 | + ```cpp | ||
| 355 | 355 | void Initialize(Local<Object> target, | |
| 356 | 356 | Local<Value> unused, | |
| 357 | 357 | Local<Context> context, | |
@@ -473,7 +473,7 @@ to perform further calls to APIs that return `Maybe`s. | |||
| 473 | 473 | A typical pattern for dealing with APIs that return `Maybe` and `MaybeLocal` is | |
| 474 | 474 | using `.ToLocal()` and `.To()` and returning early in case there is an error: | |
| 475 | 475 | ||
| 476 | - ```c++ | ||
| 476 | + ```cpp | ||
| 477 | 477 | // This could also return a v8::MaybeLocal<v8::Number>, for example. | |
| 478 | 478 | v8::Maybe<double> SumNumbers(v8::Local<v8::Context> context, | |
| 479 | 479 | v8::Local<v8::Array> array_of_integers) { | |
@@ -642,7 +642,7 @@ A helper for this is the `ASSIGN_OR_RETURN_UNWRAP` macro that returns from the | |||
| 642 | 642 | current function if unwrapping fails (typically that means that the `BaseObject` | |
| 643 | 643 | has been deleted earlier). | |
| 644 | 644 | ||
| 645 | - ```c++ | ||
| 645 | + ```cpp | ||
| 646 | 646 | void Http2Session::Request(const FunctionCallbackInfo<Value>& args) { | |
| 647 | 647 | Http2Session* session; | |
| 648 | 648 | ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder()); | |
@@ -730,7 +730,7 @@ queues once it returns. | |||
| 730 | 730 | Before calling `MakeCallback()`, it is typically necessary to enter both a | |
| 731 | 731 | `HandleScope` and a `Context::Scope`. | |
| 732 | 732 | ||
| 733 | - ```c++ | ||
| 733 | + ```cpp | ||
| 734 | 734 | void StatWatcher::Callback(uv_fs_poll_t* handle, | |
| 735 | 735 | int status, | |
| 736 | 736 | const uv_stat_t* prev, | |
@@ -822,7 +822,7 @@ The `Utf8Value`, `TwoByteValue` (i.e. UTF-16 value) and `BufferValue` | |||
| 822 | 822 | inherit from this class and allow accessing the characters in a JavaScript | |
| 823 | 823 | string this way. | |
| 824 | 824 | ||
| 825 | - ```c++ | ||
| 825 | + ```cpp | ||
| 826 | 826 | static void Chdir(const FunctionCallbackInfo<Value>& args) { | |
| 827 | 827 | Environment* env = Environment::GetCurrent(args); | |
| 828 | 828 | // ... | |
| Back | FazBrowse Home | New Git URL |
0 commit comments