Skip to content

Commit

Permalink
Finalize reamde
Browse files Browse the repository at this point in the history
  • Loading branch information
GMartigny committed May 16, 2019
1 parent 82c2f22 commit 5db0038
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Object.keys(functionsList).forEach((funcName) => {
throw error;
}
else {
console.error(error);
console.error("Fail to call native V8 function, try again with the --allow-natives-syntax flag.");
}
}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "GMartigny <guillaume.martigny@gmail.com>",
"license": "MIT",
"devDependencies": {
"@gmartigny/eslint-config": "^1.2.3",
"@gmartigny/eslint-config": "^1.2.5",
"ava": "^1.4.1",
"eslint": "^5.16.0"
}
Expand Down
38 changes: 29 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Call native V8 engine functions.

Can access all functions define in [V8 runtime](https://github.com/v8/v8/blob/master/src/runtime/runtime.h).
For brevity sake not all functions have been integrated to V8.js, if you need a function not listed [raise a new issue](https://github.com/GMartigny/v8.js/issues/new) explaining your use-case.

## Installation

npm install v8.js
Expand All @@ -12,17 +15,33 @@ V8.js exports a limited list of functions from the engine core that you can use.
In order for the package to work, you have to allow native syntax with the `--allow-natives-syntax` flag.

```js
// In index.js
const v8 = require("v8.js");

console.log(v8.getHeapUsage());
```

* Node: `node --allow-natives-syntax index.js`
* Node: `node --allow-natives-syntax file.js`
* Chrome/Chromium: `chrome --js-flags="--allow-natives-syntax"`

## API

### getHeapUsage

Return the current size of the heap in bytes.

```js
v8.getHeapUsage();
```

### collectGarbage

Trigger the internal garbage collector.

```js
v8.collectGarbage();
```

<!--
### `prepareFunctionForOptimization`
Prepare a function to be optimized by the engine. This is the first step of the optimization routine.
Expand All @@ -34,29 +53,30 @@ v8.prepareFunctionForOptimization(fn);
#### Arguments
* {Function} The function that need to be prepared.
-->


### `optimizeFunctionOnNextCall`
### optimizeFunctionOnNextCall

Set a function to be optimize on its next call. This is the second step of the optimization routine.

```js
v8.optimizeFunctionOnNextCall(fn);
v8.optimizeFunctionOnNextCall(...fns);
```

#### Arguments

* {...Function} The function set for optimization.

* {...Function} Set of functions to target for optimization.

### `getOptimizationStatus`

### getOptimizationStatus

Return integer representing the optimization status of a function in a binary flag format.

```js
v8.optimizeFunctionOnNextCall(fn);
v8.getOptimizationStatus(...fns);
```

#### Arguments

* {Function} The function set for optimization.
* {...Function} Set of functions, give the optimization status for the first one.

0 comments on commit 5db0038

Please sign in to comment.