5 * **SHALL** is used to express mandatory requirements. (negative form: **SHALL NOT**)
6 * Do not use MUST as an alternative to SHALL.
7 * **SHOULD** is used to express recommendations. (negative form: **SHOULD NOT**)
8 * **MAY** is used to express permissions . (negative form: **NEED NOT**)
9 * do not use CAN as an alternative to MAY.
15 - If a corresponding class or a similar concept exists in v8, name it with a postfix, `Wrap`.
16 The following table shows how a v8 class and its matching lwnode class are named.
19 |---------|-------------|
20 | Context | ContextWrap |
21 | Isolate | IsolateWrap |
24 - If there is a corresponding functions in v8, it **SHALL** use the exact name.
26 ContextWrap::Enter (lwnode)
30 - If not, it **SHALL** use the name starting with a small letter.
32 IsolateWrap::pushHandleScope (lwnode internal)
35 - It **SHOULD NOT** use a brand name (e.g lwnode) to name apis. Because the brand name could be changed in future.
37 - The postfix, `Ref`, stands for `Reference`. Thus, it **SHOULD NOT** use it as a pointer `Ref*`.
40 - typedef Escargot::ContextRef* JsContextRef; // (x)
43 * EscargotShim works as a bridge between V8 and Escargot. It is responsible for
44 transforming a V8 value to an Escargot value, and vice versa. This results in
45 three types of "modules" as described by the following diagram.
48 +----+ +--------------+ +----------+
49 | V8 |------| EscargotShim |------| Escargot |
50 +----+ +--------------+ +----------+
53 * We deal with a three sets of APIs, it is often confusing which value, out of three,
54 a variable refers to. To prevent this, we add a prefix when a variable is named as described below:
57 |--------------|-----------------------------------------|
58 | V8 | v8 (can be omitted if context is clear) |
62 * This naming rules **SHALL** be applied to all ``api-*.cc`` files.
64 * Within EscargotShim, `ValueWrap` **SHALL** be used for type convertion between v8 and lwnode apis.
67 ## Type conversion between lwnode world and v8 world
69 `api.cc` is like a middle land. Any value moving out from lwnode world **SHALL** be wrapped using `ValueWrap`.
74 - Wrap any value using `ValueWrap` before returning it.
77 // Escargot::ValueRef* inherited
78 auto esString = StringRef::createFromUTF8(...);
79 auto lwValue = ValueWrap::createValue(string);
80 // auto value = new ValueWrap(string); // deprecated
83 // e.g) Escargot::Script
84 auto lwValue = ValueWrap::createScript(...);
91 - Wrap any value using `ValueWrap` before use it.
94 #define VAL(that) reinterpret_cast<ValueWrap*>(that)
95 #define CVAL(that) reinterpret_cast<const ValueWrap*>(that)
98 VAL(this); // = ValueWrap(reinterpret_cast<ValueWrap*>(this));
100 // e.g) use ValueRef* from `Local<String> name`
101 VAL(*name)->value()->asString();
103 // e.g) use StringRef* from `Local<String> source_string of Source*`
104 VAL(*source->source_string)->value()->asString();
106 // e.g) access ContextWrap::Enter();
107 VAL(this)->context()->Enter();
112 * Retrun a `ValueWrap` using a `Local`
115 auto esString = StringRef::createFromUTF8(...);
117 return Utils::NewLocal<String>(isolate, esString);
120 ### Exception Handling
122 * `IsolateWrap::IsExecutionTerminating` returns true if a pending exception that should be thrown exists.
123 * Scheduling throwing an excpetion can be set through `IsolateWrap::scheduleThrow`.
124 * If a javascript operation could make an exception (e.g `v8::Object::SetPrototype`), it should do exception handling.
131 - Type names start with a capital letter and have a capital letter for each new word: `MyClass`, `MyEnum`.
134 - ``myValue_`` for a member variable
135 - ``g_myValue`` for a global variable
136 - ``s_myValue`` for a static variable
137 - ``kMyConstValue`` for a (global) constant value
140 - 2) string_value (v8)
142 - Filenames should be all lowercase and may include dashes (-).