1## Script
2
3NAN provides `v8::Script` helpers as the API has changed over the supported versions of V8.
4
5 - <a href="#api_nan_compile_script"><b><code>Nan::CompileScript()</code></b></a>
6 - <a href="#api_nan_run_script"><b><code>Nan::RunScript()</code></b></a>
7 - <a href="#api_nan_script_origin"><b><code>Nan::ScriptOrigin</code></b></a>
8
9
10<a name="api_nan_compile_script"></a>
11### Nan::CompileScript()
12
13A wrapper around [`v8::ScriptCompiler::Compile()`](https://v8docs.nodesource.com/node-8.16/da/da5/classv8_1_1_script_compiler.html#a93f5072a0db55d881b969e9fc98e564b).
14
15Note that `Nan::BoundScript` is an alias for `v8::Script`.
16
17Signature:
18
19```c++
20Nan::MaybeLocal<Nan::BoundScript> Nan::CompileScript(
21    v8::Local<v8::String> s,
22    const v8::ScriptOrigin& origin);
23Nan::MaybeLocal<Nan::BoundScript> Nan::CompileScript(v8::Local<v8::String> s);
24```
25
26
27<a name="api_nan_run_script"></a>
28### Nan::RunScript()
29
30Calls `script->Run()` or `script->BindToCurrentContext()->Run(Nan::GetCurrentContext())`.
31
32Note 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.
33
34Signature:
35
36```c++
37Nan::MaybeLocal<v8::Value> Nan::RunScript(v8::Local<Nan::UnboundScript> script)
38Nan::MaybeLocal<v8::Value> Nan::RunScript(v8::Local<Nan::BoundScript> script)
39```
40
41<a name="api_nan_script_origin"></a>
42### Nan::ScriptOrigin
43
44A class transparently extending [`v8::ScriptOrigin`](https://v8docs.nodesource.com/node-16.0/db/d84/classv8_1_1_script_origin.html#pub-methods)
45to provide backwards compatibility. Only the listed methods are guaranteed to
46be available on all versions of Node.
47
48Declaration:
49
50```c++
51class Nan::ScriptOrigin : public v8::ScriptOrigin {
52 public:
53  ScriptOrigin(v8::Local<v8::Value> name, v8::Local<v8::Integer> line = v8::Local<v8::Integer>(), v8::Local<v8::Integer> column = v8::Local<v8::Integer>())
54  v8::Local<v8::Value> ResourceName() const;
55  v8::Local<v8::Integer> ResourceLineOffset() const;
56  v8::Local<v8::Integer> ResourceColumnOffset() const;
57}
58```
59