| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7186ede commit 0bb5584
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,7 +220,7 @@ The initializer module also needs to be allowed. Consider the following example: | |||
| 220 | 220 | ```console | |
| 221 | 221 | $ node --experimental-permission t.js | |
| 222 | 222 | node:internal/modules/cjs/loader:162 | |
| 223 | - const result = internalModuleStat(filename); | ||
| 223 | + const result = internalModuleStat(receiver, filename); | ||
| 224 | 224 | ^ | |
| 225 | 225 | ||
| 226 | 226 | Error: Access to this API has been restricted | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,7 @@ will be restricted. | |||
| 48 | 48 | ```console | |
| 49 | 49 | $ node --experimental-permission index.js | |
| 50 | 50 | node:internal/modules/cjs/loader:171 | |
| 51 | - const result = internalModuleStat(filename); | ||
| 51 | + const result = internalModuleStat(receiver, filename); | ||
| 52 | 52 | ^ | |
| 53 | 53 | ||
| 54 | 54 | Error: Access to this API has been restricted | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ for example, they may not trigger garbage collection. | |||
| 24 | 24 | [`node_external_reference.h`](../../src/node_external_reference.h) file. | |
| 25 | 25 | Although, it would not start failing or crashing until the function ends up | |
| 26 | 26 | in a snapshot (either the built-in or a user-land one). Please refer to the | |
| 27 | - [binding functions documentation](../../src#binding-functions) for more | ||
| 27 | + [binding functions documentation](../../src/README.md#binding-functions) for more | ||
| 28 | 28 | information. | |
| 29 | 29 | * To test fast APIs, make sure to run the tests in a loop with a decent | |
| 30 | 30 | iterations count to trigger relevant optimizations that prefer the fast API | |
@@ -38,6 +38,23 @@ for example, they may not trigger garbage collection. | |||
| 38 | 38 | * The fast callback must be idempotent up to the point where error and fallback | |
| 39 | 39 | conditions are checked, because otherwise executing the slow callback might | |
| 40 | 40 | produce visible side effects twice. | |
| 41 | + * If the receiver is used in the callback, it must be passed as a second argument, | ||
| 42 | + leaving the first one unused, to prevent the JS land from accidentally omitting the receiver when | ||
| 43 | + invoking the fast API method. | ||
| 44 | + | ||
| 45 | + ```cpp | ||
| 46 | + // Instead of invoking the method as `receiver.internalModuleStat(input)`, the JS land should | ||
| 47 | + // invoke it as `internalModuleStat(binding, input)` to make sure the binding is available to | ||
| 48 | + // the native land. | ||
| 49 | + static int32_t FastInternalModuleStat( | ||
| 50 | + Local<Object> unused, | ||
| 51 | + Local<Object> recv, | ||
| 52 | + const FastOneByteString& input, | ||
| 53 | + FastApiCallbackOptions& options) { | ||
| 54 | + Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked()); | ||
| 55 | + // More code | ||
| 56 | + } | ||
| 57 | + ``` | ||
| 41 | 58 | ||
| 42 | 59 | ## Fallback to slow path | |
| 43 | 60 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1414,7 +1414,7 @@ function readdirSyncRecursive(basePath, options) { | |||
| 1414 | 1414 | for (let i = 0; i < readdirResult.length; i++) { | |
| 1415 | 1415 | const resultPath = pathModule.join(path, readdirResult[i]); | |
| 1416 | 1416 | const relativeResultPath = pathModule.relative(basePath, resultPath); | |
| 1417 | - const stat = binding.internalModuleStat(resultPath); | ||
| 1417 | + const stat = binding.internalModuleStat(binding, resultPath); | ||
| 1418 | 1418 | ArrayPrototypePush(readdirResults, relativeResultPath); | |
| 1419 | 1419 | // 1 indicates directory | |
| 1420 | 1420 | if (stat === 1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -914,7 +914,7 @@ async function readdirRecursive(originalPath, options) { | |||
| 914 | 914 | const { 0: path, 1: readdir } = ArrayPrototypePop(queue); | |
| 915 | 915 | for (const ent of readdir) { | |
| 916 | 916 | const direntPath = pathModule.join(path, ent); | |
| 917 | - const stat = binding.internalModuleStat(direntPath); | ||
| 917 | + const stat = binding.internalModuleStat(binding, direntPath); | ||
| 918 | 918 | ArrayPrototypePush( | |
| 919 | 919 | result, | |
| 920 | 920 | pathModule.relative(originalPath, direntPath), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,9 +235,9 @@ function stat(filename) { | |||
| 235 | 235 | const result = statCache.get(filename); | |
| 236 | 236 | if (result !== undefined) { return result; } | |
| 237 | 237 | } | |
| 238 | - const result = internalFsBinding.internalModuleStat(filename); | ||
| 238 | + const result = internalFsBinding.internalModuleStat(internalFsBinding, filename); | ||
| 239 | 239 | if (statCache !== null && result >= 0) { | |
| 240 | - // Only set cache when `internalModuleStat(filename)` succeeds. | ||
| 240 | + // Only set cache when `internalModuleStat(internalFsBinding, filename)` succeeds. | ||
| 241 | 241 | statCache.set(filename, result); | |
| 242 | 242 | } | |
| 243 | 243 | return result; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -241,8 +241,10 @@ function finalizeResolution(resolved, base, preserveSymlinks) { | |||
| 241 | 241 | throw err; | |
| 242 | 242 | } | |
| 243 | 243 | ||
| 244 | - const stats = internalFsBinding.internalModuleStat(StringPrototypeEndsWith(path, '/') ? | ||
| 245 | - StringPrototypeSlice(path, -1) : path); | ||
| 244 | + const stats = internalFsBinding.internalModuleStat( | ||
| 245 | + internalFsBinding, | ||
| 246 | + StringPrototypeEndsWith(internalFsBinding, path, '/') ? StringPrototypeSlice(path, -1) : path, | ||
| 247 | + ); | ||
| 246 | 248 | ||
| 247 | 249 | // Check for stats.isDirectory() | |
| 248 | 250 | if (stats === 1) { | |
@@ -802,6 +804,7 @@ function packageResolve(specifier, base, conditions) { | |||
| 802 | 804 | let lastPath; | |
| 803 | 805 | do { | |
| 804 | 806 | const stat = internalFsBinding.internalModuleStat( | |
| 807 | + internalFsBinding, | ||
| 805 | 808 | StringPrototypeSlice(packageJSONPath, 0, packageJSONPath.length - 13), | |
| 806 | 809 | ); | |
| 807 | 810 | // Check for !stat.isDirectory() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,7 +169,8 @@ void HistogramBase::RecordDelta(const FunctionCallbackInfo<Value>& args) { | |||
| 169 | 169 | (*histogram)->RecordDelta(); | |
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | - void HistogramBase::FastRecordDelta(Local<Value> receiver) { | ||
| 172 | + void HistogramBase::FastRecordDelta(Local<Value> unused, | ||
| 173 | + Local<Value> receiver) { | ||
| 173 | 174 | HistogramBase* histogram; | |
| 174 | 175 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 175 | 176 | (*histogram)->RecordDelta(); | |
@@ -189,7 +190,8 @@ void HistogramBase::Record(const FunctionCallbackInfo<Value>& args) { | |||
| 189 | 190 | (*histogram)->Record(value); | |
| 190 | 191 | } | |
| 191 | 192 | ||
| 192 | - void HistogramBase::FastRecord(Local<Value> receiver, | ||
| 193 | + void HistogramBase::FastRecord(Local<Value> unused, | ||
| 194 | + Local<Value> receiver, | ||
| 193 | 195 | const int64_t value, | |
| 194 | 196 | FastApiCallbackOptions& options) { | |
| 195 | 197 | if (value < 1) { | |
@@ -436,7 +438,9 @@ void IntervalHistogram::Start(const FunctionCallbackInfo<Value>& args) { | |||
| 436 | 438 | histogram->OnStart(args[0]->IsTrue() ? StartFlags::RESET : StartFlags::NONE); | |
| 437 | 439 | } | |
| 438 | 440 | ||
| 439 | - void IntervalHistogram::FastStart(Local<Value> receiver, bool reset) { | ||
| 441 | + void IntervalHistogram::FastStart(Local<Value> unused, | ||
| 442 | + Local<Value> receiver, | ||
| 443 | + bool reset) { | ||
| 440 | 444 | IntervalHistogram* histogram; | |
| 441 | 445 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 442 | 446 | histogram->OnStart(reset ? StartFlags::RESET : StartFlags::NONE); | |
@@ -448,7 +452,7 @@ void IntervalHistogram::Stop(const FunctionCallbackInfo<Value>& args) { | |||
| 448 | 452 | histogram->OnStop(); | |
| 449 | 453 | } | |
| 450 | 454 | ||
| 451 | - void IntervalHistogram::FastStop(Local<Value> receiver) { | ||
| 455 | + void IntervalHistogram::FastStop(Local<Value> unused, Local<Value> receiver) { | ||
| 452 | 456 | IntervalHistogram* histogram; | |
| 453 | 457 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 454 | 458 | histogram->OnStop(); | |
@@ -564,42 +568,45 @@ void HistogramImpl::DoReset(const FunctionCallbackInfo<Value>& args) { | |||
| 564 | 568 | (*histogram)->Reset(); | |
| 565 | 569 | } | |
| 566 | 570 | ||
| 567 | - void HistogramImpl::FastReset(Local<Value> receiver) { | ||
| 571 | + void HistogramImpl::FastReset(Local<Value> unused, Local<Value> receiver) { | ||
| 568 | 572 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 569 | 573 | (*histogram)->Reset(); | |
| 570 | 574 | } | |
| 571 | 575 | ||
| 572 | - double HistogramImpl::FastGetCount(Local<Value> receiver) { | ||
| 576 | + double HistogramImpl::FastGetCount(Local<Value> unused, Local<Value> receiver) { | ||
| 573 | 577 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 574 | 578 | return static_cast<double>((*histogram)->Count()); | |
| 575 | 579 | } | |
| 576 | 580 | ||
| 577 | - double HistogramImpl::FastGetMin(Local<Value> receiver) { | ||
| 581 | + double HistogramImpl::FastGetMin(Local<Value> unused, Local<Value> receiver) { | ||
| 578 | 582 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 579 | 583 | return static_cast<double>((*histogram)->Min()); | |
| 580 | 584 | } | |
| 581 | 585 | ||
| 582 | - double HistogramImpl::FastGetMax(Local<Value> receiver) { | ||
| 586 | + double HistogramImpl::FastGetMax(Local<Value> unused, Local<Value> receiver) { | ||
| 583 | 587 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 584 | 588 | return static_cast<double>((*histogram)->Max()); | |
| 585 | 589 | } | |
| 586 | 590 | ||
| 587 | - double HistogramImpl::FastGetMean(Local<Value> receiver) { | ||
| 591 | + double HistogramImpl::FastGetMean(Local<Value> unused, Local<Value> receiver) { | ||
| 588 | 592 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 589 | 593 | return (*histogram)->Mean(); | |
| 590 | 594 | } | |
| 591 | 595 | ||
| 592 | - double HistogramImpl::FastGetExceeds(Local<Value> receiver) { | ||
| 596 | + double HistogramImpl::FastGetExceeds(Local<Value> unused, | ||
| 597 | + Local<Value> receiver) { | ||
| 593 | 598 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 594 | 599 | return static_cast<double>((*histogram)->Exceeds()); | |
| 595 | 600 | } | |
| 596 | 601 | ||
| 597 | - double HistogramImpl::FastGetStddev(Local<Value> receiver) { | ||
| 602 | + double HistogramImpl::FastGetStddev(Local<Value> unused, | ||
| 603 | + Local<Value> receiver) { | ||
| 598 | 604 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 599 | 605 | return (*histogram)->Stddev(); | |
| 600 | 606 | } | |
| 601 | 607 | ||
| 602 | - double HistogramImpl::FastGetPercentile(Local<Value> receiver, | ||
| 608 | + double HistogramImpl::FastGetPercentile(Local<Value> unused, | ||
| 609 | + Local<Value> receiver, | ||
| 603 | 610 | const double percentile) { | |
| 604 | 611 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 605 | 612 | return static_cast<double>((*histogram)->Percentile(percentile)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,14 +101,22 @@ class HistogramImpl { | |||
| 101 | 101 | static void GetPercentilesBigInt( | |
| 102 | 102 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 103 | 103 | ||
| 104 | - static void FastReset(v8::Local<v8::Value> receiver); | ||
| 105 | - static double FastGetCount(v8::Local<v8::Value> receiver); | ||
| 106 | - static double FastGetMin(v8::Local<v8::Value> receiver); | ||
| 107 | - static double FastGetMax(v8::Local<v8::Value> receiver); | ||
| 108 | - static double FastGetMean(v8::Local<v8::Value> receiver); | ||
| 109 | - static double FastGetExceeds(v8::Local<v8::Value> receiver); | ||
| 110 | - static double FastGetStddev(v8::Local<v8::Value> receiver); | ||
| 111 | - static double FastGetPercentile(v8::Local<v8::Value> receiver, | ||
| 104 | + static void FastReset(v8::Local<v8::Value> unused, | ||
| 105 | + v8::Local<v8::Value> receiver); | ||
| 106 | + static double FastGetCount(v8::Local<v8::Value> unused, | ||
| 107 | + v8::Local<v8::Value> receiver); | ||
| 108 | + static double FastGetMin(v8::Local<v8::Value> unused, | ||
| 109 | + v8::Local<v8::Value> receiver); | ||
| 110 | + static double FastGetMax(v8::Local<v8::Value> unused, | ||
| 111 | + v8::Local<v8::Value> receiver); | ||
| 112 | + static double FastGetMean(v8::Local<v8::Value> unused, | ||
| 113 | + v8::Local<v8::Value> receiver); | ||
| 114 | + static double FastGetExceeds(v8::Local<v8::Value> unused, | ||
| 115 | + v8::Local<v8::Value> receiver); | ||
| 116 | + static double FastGetStddev(v8::Local<v8::Value> unused, | ||
| 117 | + v8::Local<v8::Value> receiver); | ||
| 118 | + static double FastGetPercentile(v8::Local<v8::Value> unused, | ||
| 119 | + v8::Local<v8::Value> receiver, | ||
| 112 | 120 | const double percentile); | |
| 113 | 121 | ||
| 114 | 122 | static void AddMethods(v8::Isolate* isolate, | |
@@ -158,10 +166,12 @@ class HistogramBase final : public BaseObject, public HistogramImpl { | |||
| 158 | 166 | static void Add(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 159 | 167 | ||
| 160 | 168 | static void FastRecord( | |
| 169 | + v8::Local<v8::Value> unused, | ||
| 161 | 170 | v8::Local<v8::Value> receiver, | |
| 162 | 171 | const int64_t value, | |
| 163 | 172 | v8::FastApiCallbackOptions& options); // NOLINT(runtime/references) | |
| 164 | - static void FastRecordDelta(v8::Local<v8::Value> receiver); | ||
| 173 | + static void FastRecordDelta(v8::Local<v8::Value> unused, | ||
| 174 | + v8::Local<v8::Value> receiver); | ||
| 165 | 175 | ||
| 166 | 176 | HistogramBase( | |
| 167 | 177 | Environment* env, | |
@@ -233,8 +243,11 @@ class IntervalHistogram final : public HandleWrap, public HistogramImpl { | |||
| 233 | 243 | static void Start(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 234 | 244 | static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 235 | 245 | ||
| 236 | - static void FastStart(v8::Local<v8::Value> receiver, bool reset); | ||
| 237 | - static void FastStop(v8::Local<v8::Value> receiver); | ||
| 246 | + static void FastStart(v8::Local<v8::Value> unused, | ||
| 247 | + v8::Local<v8::Value> receiver, | ||
| 248 | + bool reset); | ||
| 249 | + static void FastStop(v8::Local<v8::Value> unused, | ||
| 250 | + v8::Local<v8::Value> receiver); | ||
| 238 | 251 | ||
| 239 | 252 | BaseObject::TransferMode GetTransferMode() const override { | |
| 240 | 253 | return TransferMode::kCloneable; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,19 +12,25 @@ namespace node { | |||
| 12 | 12 | ||
| 13 | 13 | using CFunctionCallbackWithOneByteString = | |
| 14 | 14 | uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&); | |
| 15 | - using CFunctionCallback = void (*)(v8::Local<v8::Value> receiver); | ||
| 15 | + using CFunctionCallback = void (*)(v8::Local<v8::Value> unused, | ||
| 16 | + v8::Local<v8::Value> receiver); | ||
| 16 | 17 | using CFunctionCallbackReturnDouble = | |
| 17 | - double (*)(v8::Local<v8::Object> receiver); | ||
| 18 | + double (*)(v8::Local<v8::Object> unused, v8::Local<v8::Object> receiver); | ||
| 18 | 19 | using CFunctionCallbackReturnInt32 = | |
| 19 | - int32_t (*)(v8::Local<v8::Object> receiver, | ||
| 20 | + int32_t (*)(v8::Local<v8::Object> unused, | ||
| 21 | + v8::Local<v8::Object> receiver, | ||
| 20 | 22 | const v8::FastOneByteString& input, | |
| 21 | 23 | // NOLINTNEXTLINE(runtime/references) This is V8 api. | |
| 22 | 24 | v8::FastApiCallbackOptions& options); | |
| 23 | 25 | using CFunctionCallbackValueReturnDouble = | |
| 24 | 26 | double (*)(v8::Local<v8::Value> receiver); | |
| 25 | - using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> receiver, | ||
| 27 | + using CFunctionCallbackValueReturnDoubleUnusedReceiver = | ||
| 28 | + double (*)(v8::Local<v8::Value> unused, v8::Local<v8::Value> receiver); | ||
| 29 | + using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> unused, | ||
| 30 | + v8::Local<v8::Object> receiver, | ||
| 26 | 31 | int64_t); | |
| 27 | - using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> receiver, | ||
| 32 | + using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> unused, | ||
| 33 | + v8::Local<v8::Object> receiver, | ||
| 28 | 34 | bool); | |
| 29 | 35 | using CFunctionCallbackWithString = | |
| 30 | 36 | bool (*)(v8::Local<v8::Value>, const v8::FastOneByteString& input); | |
@@ -50,11 +56,15 @@ using CFunctionCallbackWithUint8ArrayUint32Int64Bool = | |||
| 50 | 56 | using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>, | |
| 51 | 57 | const uint32_t input); | |
| 52 | 58 | using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>, | |
| 59 | + v8::Local<v8::Value>, | ||
| 53 | 60 | const double); | |
| 54 | 61 | using CFunctionWithInt64Fallback = void (*)(v8::Local<v8::Value>, | |
| 62 | + v8::Local<v8::Value>, | ||
| 55 | 63 | const int64_t, | |
| 56 | 64 | v8::FastApiCallbackOptions&); | |
| 57 | - using CFunctionWithBool = void (*)(v8::Local<v8::Value>, bool); | ||
| 65 | + using CFunctionWithBool = void (*)(v8::Local<v8::Value>, | ||
| 66 | + v8::Local<v8::Value>, | ||
| 67 | + bool); | ||
| 58 | 68 | ||
| 59 | 69 | using CFunctionWriteString = | |
| 60 | 70 | uint32_t (*)(v8::Local<v8::Value> receiver, | |
@@ -83,6 +93,7 @@ class ExternalReferenceRegistry { | |||
| 83 | 93 | V(CFunctionCallbackReturnDouble) \ | |
| 84 | 94 | V(CFunctionCallbackReturnInt32) \ | |
| 85 | 95 | V(CFunctionCallbackValueReturnDouble) \ | |
| 96 | + V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \ | ||
| 86 | 97 | V(CFunctionCallbackWithInt64) \ | |
| 87 | 98 | V(CFunctionCallbackWithBool) \ | |
| 88 | 99 | V(CFunctionCallbackWithString) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments