Ai
1 Star 1 Fork 0

ScSofts/quickjspp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
value.cpp 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
ftk 提交于 2019-09-22 17:45 +08:00 . more tests
#include "quickjspp.hpp"
#include <iostream>
#include <cstring>
int main()
{
qjs::Runtime runtime;
qjs::Context context(runtime);
try
{
auto val1 = context.newValue(321);
auto val2 = context.newValue(123);
assert(val1 != val2);
val1 = val2;
assert(val1 == val2);
val1 = context.newValue(123);
assert(val1 == val2);
val1 = std::move(val2);
assert(val1 != val2);
assert(val1.as<std::string>() == "123");
assert((double) val1 == 123.0);
val2 = context.newValue((std::string) "123");
assert(val1 != val2);
context.global()["val1"] = val1;
context.global()["val2"] = val2;
assert((bool) context.eval("val1 !== val2"));
assert((bool) context.eval("val1 == val2"));
//
val1 = context.newObject();
val1["a"] = "1";
val2 = context.newObject();
val2["a"] = "1";
assert(val1 != val2);
context.global()["val1"] = val1;
context.global()["val2"] = val2;
assert((bool) context.eval("val1 !== val2"));
assert((bool) context.eval("val1 != val2"));
assert((bool)context.eval("JSON.stringify(val1) === JSON.stringify(val2)"));
qjs::Value one = val1["a"];
assert((int)one == 1);
}
catch(qjs::exception)
{
auto exc = context.getException();
std::cerr << (exc.isError() ? "Error: " : "Throw: ") << (std::string) exc << std::endl;
if((bool) exc["stack"])
std::cerr << (std::string) exc["stack"] << std::endl;
return 1;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gitnow/quickjspp.git
git@gitee.com:gitnow/quickjspp.git
gitnow
quickjspp
quickjspp
master

搜索帮助