Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error / exception handling #10

Merged
merged 8 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename context -> object
It's going to get confused with external contexts.
  • Loading branch information
mikee47 committed Dec 23, 2021
commit b5f3bf9aae285bddd779f89cb137e3260c63ef9d
4 changes: 2 additions & 2 deletions samples/Event_Jsvm/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ bool triggerEvent(const String& name, const JS::Object& params)
event["name"] = name;
event["params"] = params;

auto context = JS::global();
auto object = JS::global();
for(auto& listener : events[name]) {
listener.call(context, event);
listener.call(object, event);
}

return true;
Expand Down
14 changes: 7 additions & 7 deletions test/modules/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class EventTest : public TestGroup
{
JS::initialise();

auto context = JS::global();
auto object = JS::global();

TEST_CASE("Start VM")
{
DEFINE_FSTR_LOCAL(FS_moduleLoaded, "OK, module loaded!");
DEFINE_FSTR_LOCAL(FS_addEventListener, "addEventListener");
REQUIRE(FS_moduleLoaded == JS::Snapshot::load(eventSnap));
REQUIRE(context.registerFunction(FS_addEventListener, addEventListener));
REQUIRE(!context.runFunction("init").isError());
REQUIRE(object.registerFunction(FS_addEventListener, addEventListener));
REQUIRE(!object.runFunction("init").isError());
}

TEST_CASE("Create error")
Expand All @@ -69,13 +69,13 @@ class EventTest : public TestGroup
JS::Value res;
JS::Value prop;

res = listeners[0].call(context, event);
res = listeners[0].call(object, event);
printValue(F("listeners[0].call"), res);
REQUIRE_EQ(res.type(), JS::Type::String);
REQUIRE_EQ(res.as<String>(), "one");

arg2["value"] = true;
res = listeners[1].call(context, {event, arg2});
res = listeners[1].call(object, {event, arg2});
printValue(F("listeners[1].call"), res);
REQUIRE_EQ(res.type(), JS::Type::Number);
REQUIRE_EQ(res.as<unsigned>(), 2);
Expand All @@ -84,7 +84,7 @@ class EventTest : public TestGroup
REQUIRE_EQ(prop.as<unsigned>(), 2);

arg2["value"] = 12.5;
res = listeners[2].call(context, {event, arg2});
res = listeners[2].call(object, {event, arg2});
printValue(F("listeners[2].call"), res);
REQUIRE_EQ(res.type(), JS::Type::Number);
REQUIRE_EQ(res.as<float>(), 3.5);
Expand All @@ -97,7 +97,7 @@ class EventTest : public TestGroup

TEST_CASE("Shutdown VM")
{
context.reset();
object.reset();
events.clear();
JS::cleanup();

Expand Down
10 changes: 5 additions & 5 deletions test/modules/fatal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FatalTest : public TestGroup
{
JS::initialise();

auto context = JS::global();
auto object = JS::global();

#ifndef JERRY_ESNEXT
TEST_CASE("Bad bytecode")
Expand All @@ -45,7 +45,7 @@ class FatalTest : public TestGroup
{
debug_i("%s", String(e).c_str());
}
auto res = context.runFunction("init");
auto res = object.runFunction("init");
printValue("runFunction", res);
REQUIRE(res.isError());
}
Expand All @@ -56,15 +56,15 @@ class FatalTest : public TestGroup
auto res = JS::Snapshot::load(fatalSnap);
printValue("res", res);
REQUIRE(!res.isError());
REQUIRE(context.registerFunction("throwTantrum", throwTantrum));
REQUIRE(object.registerFunction("throwTantrum", throwTantrum));
}

TEST_CASE("Memory")
{
JS::Object dbg;
JS_TRY()
{
context.runFunction("allocateArray", {4000, 3.5, dbg});
object.runFunction("allocateArray", {4000, 3.5, dbg});
TEST_ASSERT(false);
}
JS_CATCH()
Expand All @@ -76,7 +76,7 @@ class FatalTest : public TestGroup

TEST_CASE("Shutdown VM")
{
context.reset();
object.reset();
JS::cleanup();
auto heapUsed = JS::getHeapUsed();
debug_i("Heap used: %u", heapUsed);
Expand Down