Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/embind/test_val_assignment.cpp
4150 views
1
#include <emscripten/val.h>
2
3
using emscripten::val;
4
5
int main() {
6
val obj = val::object();
7
// Code like below doesn't work like the user might expect.
8
// `obj[...] = ...` only modifies the on-stack `val` binding, whereas user probably wanted to set the property on the actual JS object.
9
// The correct way to set the property is via `val::set()` instead, like `obj.set("foo", 42)`.
10
// Test here that we help catch this mistake and produce a compilation error for the line below.
11
obj["foo"] = val(42);
12
}
13
14