-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Build | ||
build/ | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"C:\\Users\\Game\\AppData\\Local\\node-gyp\\Cache\\15.1.0\\include\\node" | ||
], | ||
"defines": [ | ||
"_DEBUG", | ||
"UNICODE", | ||
"_UNICODE" | ||
], | ||
"windowsSdkVersion": "10.0.18362.0", | ||
"compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\bin\\Hostx64\\x64\\cl.exe", | ||
"cStandard": "c17", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "windows-msvc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "internal", | ||
"sources": [ "src/internal.cpp" ], | ||
"include_dirs": [ "node_modules/nan" ] | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "internal-prop", | ||
"version": "1.0.0", | ||
"description": "Gives access to native objects internal properties, such as proxy's [[Target]] and [[Handler]]", | ||
"main": "src/main.js", | ||
"scripts": { | ||
"save": "npm publish & push" | ||
}, | ||
"keywords": [ | ||
"proxy", | ||
"jsproxy", | ||
"promise", | ||
"internal", | ||
"native", | ||
"target", | ||
"handler", | ||
"resonse", | ||
"status" | ||
], | ||
"author": "AFatNiBBa", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# internal-prop | ||
Gives access to native objects internal properties, such as a proxy's `[[Target]]` or `[[Handler]]` | ||
|
||
## Warning | ||
This module is native, it means that it contains c++ code that gets compiled every time the module is installed to ensure that the binaries can be read by your machine, the problem is that node apparently uses external tools that may be not present in your machine | ||
|
||
## Usage | ||
The module gives you indipendent functions that you can use to extract internal properties of objects | ||
```js | ||
const { fromProxy, fromPromise } = require("internal-prop"); | ||
``` | ||
Each function accept an object and returns an array of its internal properties <br> | ||
If the object is not of the correct type (e.g. `fromProxy(obj)` wants `obj` to be a proxy) the function will return `null` | ||
|
||
## Supported | ||
- **`Proxy`** | ||
- `fromProxy()` function | ||
- The array contains the `[[Target]]` and then the `[[Handler]]` | ||
- **`Promise`** | ||
- `fromPromise()` function | ||
- The array contains the `[[PromiseState]]` and then the `[[PromiseResult]]` | ||
- The values can be: | ||
- `"fulfilled"` and the result of the promise | ||
- `"pending"` and `null` | ||
- `"rejected"` and the error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
#include <node.h> | ||
|
||
using namespace v8; | ||
|
||
/** | ||
* If the given object is a proxy it returns an array of the [[Target]] and the [[Handler]]. | ||
* If the object is not a proxy it returns 'null'. | ||
*/ | ||
void fromProxy(const FunctionCallbackInfo<Value> &info) { | ||
Isolate* isolate = info.GetIsolate(); | ||
if (!info[0]->IsProxy()) | ||
info.GetReturnValue().Set(Null(isolate)); | ||
else | ||
{ | ||
Local<Proxy> temp = Local<Proxy>::Cast(info[0]); | ||
Local<Value> out[] = { | ||
temp->GetTarget(), | ||
temp->GetHandler() | ||
}; | ||
info.GetReturnValue().Set(Array::New(isolate, out, 2)); | ||
} | ||
} | ||
|
||
/** | ||
* If the given object is a promise it returns an array of the [[PromiseState]] and the [[PromiseResult]]. | ||
* If the state is "pending" the result will be 'null'. | ||
* If the object is not a promise it returns 'null'. | ||
*/ | ||
void fromPromise(const FunctionCallbackInfo<Value> &info) { | ||
Isolate* isolate = info.GetIsolate(); | ||
if (!info[0]->IsPromise()) | ||
info.GetReturnValue().Set(Null(isolate)); | ||
else | ||
{ | ||
Local<Promise> temp = Local<Promise>::Cast(info[0]); | ||
Promise::PromiseState state = temp->State(); | ||
Local<Value> out[] = { | ||
String::NewFromUtf8(isolate, ( | ||
state == Promise::PromiseState::kFulfilled | ||
? "fulfilled" | ||
: state == Promise::PromiseState::kPending | ||
? "pending" | ||
: "rejected" | ||
)).ToLocalChecked(), | ||
state == Promise::PromiseState::kPending | ||
? (Local<Value>)Null(isolate) | ||
: temp->Result() | ||
}; | ||
info.GetReturnValue().Set(Array::New(isolate, out, 2)); | ||
} | ||
} | ||
|
||
void init(Local<Object> exports, Local<Value> module, void* context) { | ||
NODE_SET_METHOD(exports, "fromProxy", fromProxy); | ||
NODE_SET_METHOD(exports, "fromPromise", fromPromise); | ||
} | ||
|
||
NODE_MODULE(internal, init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
module.exports = require(`../build/Release/internal.node`); |