You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.. COMMENT (Not rendered) : This created from val.h header file on 10 Aug 2014-03
3
+
=====
4
+
val.h
5
+
=====
8
6
9
7
The *Embind* C++ class :cpp:class:`emscripten::val` (defined in `val.h <https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/val.h>`_) is used to *transliterate* JavaScript code to C++.
10
8
@@ -31,7 +29,7 @@ Guide material for this class can be found in :ref:`embind-val-guide`.
You can test whether the ``open`` method call was successful using :cpp:func:`~emscripten::val::operator[]` to read an object property, then :cpp:func:`~emscripten::val::as` to coerce the type:
37
35
@@ -48,7 +46,16 @@ Guide material for this class can be found in :ref:`embind-val-guide`.
48
46
}
49
47
50
48
See :ref:`embind-val-guide` for other examples.
49
+
50
+
51
+
.. warning:: JavaScript values can't be shared across threads, so neither can ``val`` instances that bind them.
52
+
53
+
For example, if you want to cache some JavaScript global as a ``val``, you need to retrieve and bind separate instances of that global by its name in each thread.
54
+
The easiest way to do this is with a ``thread_local`` declaration:
55
+
56
+
.. code:: cpp
51
57
58
+
thread_local const val Uint8Array = val::global("Uint8Array");
52
59
53
60
.. todo::
54
61
@@ -74,193 +81,129 @@ Guide material for this class can be found in :ref:`embind-val-guide`.
74
81
75
82
Creates and returns a new ``Array``.
76
83
77
-
:returns: The new ``Array``.
78
-
79
84
80
85
.. cpp:function::static val object()
81
86
82
87
Creates and returns a new ``Object``.
83
88
84
-
:returns: The new ``Object``.
85
-
86
89
87
90
.. cpp:function::static val undefined()
88
91
89
92
Creates a ``val`` that represents ``undefined``.
90
93
91
-
:returns: The ``val`` that represents ``undefined``.
92
-
93
94
94
95
.. cpp:function::static val null()
95
96
96
-
Creates a ``val`` that represents ``null``. ``val::undefined()`` is the same, but for undefined.
97
-
98
-
:returns: A ``val`` that represents ``null``.
99
-
100
-
101
-
.. cpp:function::static val take_ownership(internal::EM_VAL e)
102
-
103
-
**HamishW**-Replace with description.
104
-
105
-
:returns: **HamishW**-Replace with description.
97
+
Creates a ``val`` that represents ``null``.
106
98
107
99
108
100
.. cpp:function::static val global(const char* name)
109
101
110
-
Looks up a global symbol.
111
-
112
-
:param const char* name: **HamishW**-Replace with description.
113
-
:returns: **HamishW**-Replace with description.
102
+
Looks up a global value by the specified ``name``.
114
103
115
104
116
105
117
106
.. cpp:function::static val module_property(const char* name)
118
107
119
-
Looks up a symbol on the emscripten Module object.
120
-
121
-
:param const char* name: **HamishW**-Replace with description.
122
-
:returns: **HamishW**-Replace with description.
108
+
Looks up a value by the provided ``name`` on the Emscripten Module object.
123
109
124
110
125
111
.. cpp:function::explicitval(T&& value)
126
112
127
113
Constructor.
128
114
129
-
A ``val`` can be constructed by explicit construction from any C++ type. For example, ``val(true)`` or ``val(std::string("foo"))``.
130
-
131
-
:param T&& value: Any C++ type.
132
-
133
-
134
-
**HamishW** Don't know how following "floating statement works". Leaving here for discussion
135
-
``val() = delete;``
115
+
Creates a ``val`` by conversion from any Embind-compatible C++ type.
116
+
For example, ``val(true)`` or ``val(std::string("foo"))``.
136
117
137
118
138
119
.. cpp:function::explicitval(const char* v)
139
120
140
-
**HamishW**-Replace with description.
141
-
142
-
:param const char* v: **HamishW**-Replace with description.
121
+
Constructs a ``val`` instance from a string literal.
143
122
144
123
145
124
.. cpp:function:: val(val&& v)
146
-
147
-
**HamishW**-Replace with description.
148
-
149
-
:param val&& v: **HamishW**-Replace with description.
125
+
126
+
Moves ownership of a value to a new ``val`` instance.
150
127
151
128
152
129
.. cpp:function:: val(const val& v)
153
-
154
-
**HamishW**-Replace with description.
155
-
156
-
:param const val& v: **HamishW**-Replace with description.
130
+
131
+
Creates another reference to the same value behind the provided ``val`` instance.
157
132
158
133
159
134
.. cpp:function::~val()
160
135
161
-
Destructor. **HamishW**-Replace with further description or delete comment.
136
+
Removes the currently bound value by decreasing its refcount.
162
137
163
138
164
139
.. cpp:function:: val& operator=(val&& v)
165
-
166
-
**HamishW**-Replace with description.
167
-
168
-
:param val&& v: **HamishW**-Replace with description.
169
-
:returns: **HamishW**-Replace with description.
140
+
141
+
Removes a reference to the currently bound value and takes over the provided one.
170
142
171
143
172
144
.. cpp:function:: val& operator=(const val& v)
173
145
174
-
**HamishW**-Replace with description.
175
-
176
-
:param val&& v: **HamishW**-Replace with description.
177
-
:returns: **HamishW**-Replace with description.
146
+
Removes a reference to the currently bound value and creates another reference to
0 commit comments