代码拉取完成,页面将自动刷新
#include "quickjspp.hpp"
#include <iostream>
struct A{};
int main()
{
qjs::Runtime runtime;
qjs::Context context(runtime);
context.global().add("println", [](const std::string& s) { std::cout << s << std::endl; });
context.registerClass<A>("A");
context.registerClass<A>("A");
try
{
auto obj = context.eval("Symbol.toPrimitive");
std::cout << static_cast<int>(obj) << std::endl;
assert(false);
}
catch(qjs::exception)
{
auto exc = context.getException();
assert(exc.isError() && (std::string) exc == "TypeError: cannot convert symbol to number");
}
try
{
std::string big;
big.resize((1 << 30) + 1);
auto fun = context.eval("(function(a, b, c) { println(a); println(b); println(c); })").as<std::function<void(double, std::string, int)>>();
fun(0, std::move(big), 0);
assert(false);
}
catch(qjs::exception)
{
auto exc = context.getException();
std::cout << (std::string) exc << '\n' << (std::string_view) exc["stack"];
}
try
{
//context.global().add("emptyf", [](JSValue v) {} );
auto f = (std::function<void ()>) context.eval("(function() { +Symbol.toPrimitive })");
f();
assert(false);
}
catch(qjs::exception)
{
auto exc = context.getException();
std::cout << (std::string) exc << '\n' << (std::string_view) exc["stack"];
}
try
{
qjs::Value function = context.eval("() => { let a = b; }", "<test>");
auto native = function.as<std::function<qjs::Value()>>();
qjs::Value result = native();
assert(false);
}
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;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。