2020-06-02 10:14:03 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
extern "C" {
|
2020-09-14 07:40:49 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2020-09-25 12:39:30 +00:00
|
|
|
#include <stdlib.h>
|
2020-09-14 07:40:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2020-06-02 10:14:03 +00:00
|
|
|
#include "libreprl.h"
|
2020-09-14 07:40:49 +00:00
|
|
|
|
2020-09-25 12:39:30 +00:00
|
|
|
struct reprl_context* ctx;
|
|
|
|
|
|
|
|
int execute(const char* code) {
|
|
|
|
uint64_t exec_time;
|
|
|
|
return reprl_execute(ctx, code, strlen(code), 1000, &exec_time, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect_success(const char* code) {
|
|
|
|
if (execute(code) != 0) {
|
|
|
|
printf("Execution of \"%s\" failed\n", code);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect_failure(const char* code) {
|
|
|
|
if (execute(code) == 0) {
|
|
|
|
printf("Execution of \"%s\" unexpectedly succeeded\n", code);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 07:40:49 +00:00
|
|
|
int main(int argc, char** argv) {
|
2020-09-25 12:39:30 +00:00
|
|
|
ctx = reprl_create_context();
|
2020-09-14 07:40:49 +00:00
|
|
|
|
|
|
|
const char* env[] = {nullptr};
|
|
|
|
const char* prog = argc > 1 ? argv[1] : "./out.gn/x64.debug/d8";
|
|
|
|
const char* args[] = {prog, nullptr};
|
|
|
|
if (reprl_initialize_context(ctx, args, env, 1, 1) != 0) {
|
|
|
|
printf("REPRL initialization failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Basic functionality test
|
2020-09-25 12:39:30 +00:00
|
|
|
if (execute("let greeting = \"Hello World!\";") != 0) {
|
|
|
|
printf(
|
|
|
|
"Script execution failed, is %s the path to d8 built with "
|
|
|
|
"v8_fuzzilli=true?\n",
|
|
|
|
prog);
|
2020-09-14 07:40:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that runtime exceptions can be detected
|
2020-09-25 12:39:30 +00:00
|
|
|
expect_failure("throw 'failure';");
|
2020-09-14 07:40:49 +00:00
|
|
|
|
|
|
|
// Verify that existing state is property reset between executions
|
2020-09-25 12:39:30 +00:00
|
|
|
expect_success("globalProp = 42; Object.prototype.foo = \"bar\";");
|
|
|
|
expect_success("if (typeof(globalProp) !== 'undefined') throw 'failure'");
|
|
|
|
expect_success("if (typeof(({}).foo) !== 'undefined') throw 'failure'");
|
|
|
|
|
|
|
|
// Verify that rejected promises are properly reset between executions
|
|
|
|
expect_failure("async function fail() { throw 42; }; fail()");
|
|
|
|
expect_success("42");
|
|
|
|
expect_failure("async function fail() { throw 42; }; fail()");
|
2020-09-14 07:40:49 +00:00
|
|
|
|
|
|
|
puts("OK");
|
2020-06-02 10:14:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-14 07:40:49 +00:00
|
|
|
}
|