summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaƂ Sabiniarz <31597105+mhvsa@users.noreply.github.com>2019-06-07 02:51:04 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-06-06 21:51:04 -0400
commit9bea576f3ea224ec72f371f6f0bc582171ca7890 (patch)
tree17a0dbfd8f463ca93e7240e13ec6cbf2bad4b751
parente3b2205eba2851380a9a149071cb4fb7e8218b13 (diff)
Deno.core.evalContext & Deno.core.print fix (#2465)
-rw-r--r--core/libdeno/binding.cc12
-rw-r--r--core/libdeno/exceptions.cc5
-rw-r--r--core/libdeno/exceptions.h2
-rw-r--r--core/libdeno/libdeno_test.cc14
-rw-r--r--core/libdeno/libdeno_test.js24
5 files changed, 54 insertions, 3 deletions
diff --git a/core/libdeno/binding.cc b/core/libdeno/binding.cc
index 4aeb6003a..f8ef1c7a7 100644
--- a/core/libdeno/binding.cc
+++ b/core/libdeno/binding.cc
@@ -96,9 +96,11 @@ void PromiseRejectCallback(v8::PromiseRejectMessage promise_reject_message) {
}
void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
- CHECK_GE(args.Length(), 1);
- CHECK_LE(args.Length(), 3);
auto* isolate = args.GetIsolate();
+ int argsLen = args.Length();
+ if (argsLen < 1 || argsLen > 2) {
+ ThrowInvalidArgument(isolate);
+ }
DenoIsolate* d = DenoIsolate::FromIsolate(isolate);
auto context = d->context_.Get(d->isolate_);
v8::HandleScope handle_scope(isolate);
@@ -375,7 +377,11 @@ void EvalContext(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto context = d->context_.Get(isolate);
v8::Context::Scope context_scope(context);
- CHECK(args[0]->IsString());
+ if (!(args[0]->IsString())) {
+ ThrowInvalidArgument(isolate);
+ return;
+ }
+
auto source = args[0].As<v8::String>();
auto output = v8::Array::New(isolate, 2);
diff --git a/core/libdeno/exceptions.cc b/core/libdeno/exceptions.cc
index 85f0ca340..8f5779acd 100644
--- a/core/libdeno/exceptions.cc
+++ b/core/libdeno/exceptions.cc
@@ -214,4 +214,9 @@ void HandleExceptionMessage(v8::Local<v8::Context> context,
CHECK_NOT_NULL(d);
d->last_exception_ = json_str;
}
+
+void ThrowInvalidArgument(v8::Isolate* isolate) {
+ isolate->ThrowException(v8::Exception::TypeError(v8_str("Invalid Argument")));
+}
+
} // namespace deno
diff --git a/core/libdeno/exceptions.h b/core/libdeno/exceptions.h
index e07ff183a..413bcb7ef 100644
--- a/core/libdeno/exceptions.h
+++ b/core/libdeno/exceptions.h
@@ -18,6 +18,8 @@ void HandleException(v8::Local<v8::Context> context,
void HandleExceptionMessage(v8::Local<v8::Context> context,
v8::Local<v8::Message> message);
+
+void ThrowInvalidArgument(v8::Isolate* isolate);
} // namespace deno
#endif // EXCEPTIONS_H_
diff --git a/core/libdeno/libdeno_test.cc b/core/libdeno/libdeno_test.cc
index e09a973b2..485c95bff 100644
--- a/core/libdeno/libdeno_test.cc
+++ b/core/libdeno/libdeno_test.cc
@@ -235,6 +235,20 @@ TEST(LibDenoTest, LibDenoEvalContextError) {
deno_delete(d);
}
+TEST(LibDenoTest, LibDenoEvalContextInvalidArgument) {
+ Deno* d = deno_new(deno_config{0, snapshot, empty, nullptr, nullptr});
+ deno_execute(d, nullptr, "a.js", "LibDenoEvalContextInvalidArgument();");
+ EXPECT_EQ(nullptr, deno_last_exception(d));
+ deno_delete(d);
+}
+
+TEST(LibDenoTest, LibDenoPrintInvalidArgument) {
+ Deno* d = deno_new(deno_config{0, snapshot, empty, nullptr, nullptr});
+ deno_execute(d, nullptr, "a.js", "LibDenoPrintInvalidArgument();");
+ EXPECT_EQ(nullptr, deno_last_exception(d));
+ deno_delete(d);
+}
+
TEST(LibDenoTest, SharedAtomics) {
int32_t s[] = {0, 1, 2};
deno_buf shared = {reinterpret_cast<uint8_t*>(s), sizeof s};
diff --git a/core/libdeno/libdeno_test.js b/core/libdeno/libdeno_test.js
index 156af1e47..17a6343cf 100644
--- a/core/libdeno/libdeno_test.js
+++ b/core/libdeno/libdeno_test.js
@@ -195,3 +195,27 @@ global.LibDenoEvalContextError = () => {
assert(!errInfo5.isCompileError); // is NOT a compilation error! (just eval)
assert(errInfo5.thrown.message === "Unexpected end of input");
};
+
+global.LibDenoEvalContextInvalidArgument = () => {
+ try {
+ Deno.core.evalContext();
+ } catch (e) {
+ assert(e instanceof TypeError);
+ assert(e.message === "Invalid Argument");
+ }
+};
+
+global.LibDenoPrintInvalidArgument = () => {
+ try {
+ Deno.core.print();
+ } catch (e) {
+ assert(e instanceof TypeError);
+ assert(e.message === "Invalid Argument");
+ }
+ try {
+ Deno.core.print(2, 3, 4);
+ } catch (e) {
+ assert(e instanceof TypeError);
+ assert(e.message === "Invalid Argument");
+ }
+};