ff68959b1d17e6a639293d85c1eff1cd01381494656cc8ab4c8729ffe332d3ba9c9baaeafa3b2527310c20a5da633a840b227a7ac03bdb89ac35491c4b4b68 2.0 KB

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