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,13 @@ 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 aren't shared across threads, so neither can ``val``. If you want to create a ``val`` binding to some JavaScript value and access it from multiple threads, you must create a unique binding per each thread using e.g. ``thread_local``:
52
+
53
+
.. code:: cpp
51
54
55
+
thread_local const val Uint8Array = val::global("Uint8Array");
52
56
53
57
.. todo::
54
58
@@ -74,193 +78,129 @@ Guide material for this class can be found in :ref:`embind-val-guide`.
74
78
75
79
Creates and returns a new ``Array``.
76
80
77
-
:returns: The new ``Array``.
78
-
79
81
80
82
.. cpp:function::static val object()
81
83
82
84
Creates and returns a new ``Object``.
83
85
84
-
:returns: The new ``Object``.
85
-
86
86
87
87
.. cpp:function::static val undefined()
88
88
89
89
Creates a ``val`` that represents ``undefined``.
90
90
91
-
:returns: The ``val`` that represents ``undefined``.
92
-
93
91
94
92
.. cpp:function::static val null()
95
93
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.
94
+
Creates a ``val`` that represents ``null``.
106
95
107
96
108
97
.. cpp:function::static val global(const char* name)
109
98
110
-
Looks up a global symbol.
111
-
112
-
:param const char* name: **HamishW**-Replace with description.
113
-
:returns: **HamishW**-Replace with description.
99
+
Looks up a global value by the specified ``name``.
114
100
115
101
116
102
117
103
.. cpp:function::static val module_property(const char* name)
118
104
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.
105
+
Looks up a value by the provided ``name`` on the Emscripten Module object.
123
106
124
107
125
108
.. cpp:function::explicitval(T&& value)
126
109
127
110
Constructor.
128
111
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;``
112
+
Creates a ``val`` by conversion from any Embind-compatible C++ type.
113
+
For example, ``val(true)`` or ``val(std::string("foo"))``.
136
114
137
115
138
116
.. cpp:function::explicitval(const char* v)
139
117
140
-
**HamishW**-Replace with description.
141
-
142
-
:param const char* v: **HamishW**-Replace with description.
118
+
Constructs a ``val`` instance from a string literal.
143
119
144
120
145
121
.. cpp:function:: val(val&& v)
146
-
147
-
**HamishW**-Replace with description.
148
-
149
-
:param val&& v: **HamishW**-Replace with description.
122
+
123
+
Moves ownership of a value to a new ``val`` instance.
150
124
151
125
152
126
.. cpp:function:: val(const val& v)
153
-
154
-
**HamishW**-Replace with description.
155
-
156
-
:param const val& v: **HamishW**-Replace with description.
127
+
128
+
Creates another reference to the same value behind the provided ``val`` instance.
157
129
158
130
159
131
.. cpp:function::~val()
160
132
161
-
Destructor. **HamishW**-Replace with further description or delete comment.
133
+
Removes the currently bound value by decreasing its refcount.
162
134
163
135
164
136
.. 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.
137
+
138
+
Removes a reference to the currently bound value and takes over the provided one.
170
139
171
140
172
141
.. cpp:function:: val& operator=(const val& v)
173
142
174
-
**HamishW**-Replace with description.
175
-
176
-
:param val&& v: **HamishW**-Replace with description.
177
-
:returns: **HamishW**-Replace with description.
143
+
Removes a reference to the currently bound value and creates another reference to
0 commit comments