jerryscript/src/include/Jerryscript/VirtualMachine.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * VirtualMachine.h
8  *
9  * @author Nov 2021 - Slavey Karadzhov <slav@attachix.com>
10  */
11 
12 #pragma once
13 
14 #include "Types.h"
15 #include <FileSystem.h>
16 #include <Platform/Clocks.h>
17 
18 namespace Jerryscript
19 {
23 void initialise(jerry_init_flag_t flags = JERRY_INIT_EMPTY);
24 
31 void cleanup();
32 
38 inline bool isFeatureEnabled(Feature feature)
39 {
40  return jerry_is_feature_enabled(jerry_feature_t(feature));
41 }
42 
43 namespace Watchdog
44 {
49 void setPeriod(unsigned milliseconds);
50 
57 
58 }; // namespace Watchdog
59 
60 /*
61  * @brief Parses the JavaScript code and prepares it for execution
62  * @retval bool true on success
63  *
64  * Requires jerryscript to be compiled with parsing enabled.
65  */
66 Value eval(const String& jsCode);
67 
71 namespace Snapshot
72 {
84 Value load(const uint32_t* snapshot, size_t snapshotSize);
85 
91 inline Value load(const String& snapshot)
92 {
93  return load(reinterpret_cast<const uint32_t*>(snapshot.c_str()), snapshot.length());
94 }
95 
101 inline Value loadFromFile(const String& fileName)
102 {
103  return load(fileGetContent(fileName));
104 }
105 
108 } // namespace Snapshot
109 
113 inline void gc(bool maximumEffort = false)
114 {
115  jerry_gc(maximumEffort ? JERRY_GC_PRESSURE_HIGH : JERRY_GC_PRESSURE_LOW);
116 }
117 
118 } // namespace Jerryscript
Value
Definition: Components/IFS/src/include/IFS/Error.h:82
The String class.
Definition: WString.h:136
void cleanup()
Clean up the virtual machine by unloading snapshots, freeing allocated memory, etc.
Timer2Clock::Ticks< uint32_t > read()
Get elapsed watchdog time since last reset.
Definition: Libraries/jerryscript/src/include/Jerryscript/Context.h:123
void setPeriod(unsigned milliseconds)
Set watchdog period.
bool isFeatureEnabled(Feature feature)
Check if optional feature is available.
Definition: jerryscript/src/include/Jerryscript/VirtualMachine.h:47
void initialise(jerry_init_flag_t flags=JERRY_INIT_EMPTY)
Initializes the JavaScript VM.
Value eval(const String &jsCode)
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:616
Value load(const uint32_t *snapshot, size_t snapshotSize)
Load from memory buffer.
Feature
Definition: Libraries/jerryscript/src/include/Jerryscript/Types.h:56
Value loadFromFile(const String &fileName)
Load a snapshot from file and execute it.
Definition: jerryscript/src/include/Jerryscript/VirtualMachine.h:110
String fileGetContent(const TFileName &fileName)
Read content of a file.
Definition: Core/FileSystem.h:313
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:243
void gc(bool maximumEffort=false)
Perform memory garbage collection.
Definition: jerryscript/src/include/Jerryscript/VirtualMachine.h:122