package.doc.script.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nan Show documentation
Show all versions of nan Show documentation
Native Abstractions for Node.js: C++ header for Node 0.8 -> 18 compatibility
## Script
NAN provides `v8::Script` helpers as the API has changed over the supported versions of V8.
- Nan::CompileScript()
- Nan::RunScript()
- Nan::ScriptOrigin
### Nan::CompileScript()
A wrapper around [`v8::ScriptCompiler::Compile()`](https://v8docs.nodesource.com/node-8.16/da/da5/classv8_1_1_script_compiler.html#a93f5072a0db55d881b969e9fc98e564b).
Note that `Nan::BoundScript` is an alias for `v8::Script`.
Signature:
```c++
Nan::MaybeLocal Nan::CompileScript(
v8::Local s,
const v8::ScriptOrigin& origin);
Nan::MaybeLocal Nan::CompileScript(v8::Local s);
```
### Nan::RunScript()
Calls `script->Run()` or `script->BindToCurrentContext()->Run(Nan::GetCurrentContext())`.
Note that `Nan::BoundScript` is an alias for `v8::Script` and `Nan::UnboundScript` is an alias for `v8::UnboundScript` where available and `v8::Script` on older versions of V8.
Signature:
```c++
Nan::MaybeLocal Nan::RunScript(v8::Local script)
Nan::MaybeLocal Nan::RunScript(v8::Local script)
```
### Nan::ScriptOrigin
A class transparently extending [`v8::ScriptOrigin`](https://v8docs.nodesource.com/node-16.0/db/d84/classv8_1_1_script_origin.html#pub-methods)
to provide backwards compatibility. Only the listed methods are guaranteed to
be available on all versions of Node.
Declaration:
```c++
class Nan::ScriptOrigin : public v8::ScriptOrigin {
public:
ScriptOrigin(v8::Local name, v8::Local line = v8::Local(), v8::Local column = v8::Local())
v8::Local ResourceName() const;
v8::Local ResourceLineOffset() const;
v8::Local ResourceColumnOffset() const;
}
```
© 2015 - 2024 Weber Informatics LLC | Privacy Policy