Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/wasm/wasm-macro-gen.h" | |
| 6 | |
| 7 #include "test/cctest/cctest.h" | |
| 8 #include "test/cctest/compiler/value-helper.h" | |
| 9 #include "test/cctest/wasm/test-signatures.h" | |
| 10 #include "test/cctest/wasm/wasm-run-utils.h" | |
| 11 | |
| 12 using namespace v8::base; | |
| 13 using namespace v8::internal; | |
| 14 using namespace v8::internal::compiler; | |
| 15 using namespace v8::internal::wasm; | |
| 16 | |
| 17 using v8::Local; | |
| 18 using v8::Utils; | |
| 19 | |
| 20 namespace { // anonymous | |
|
JF
2016/04/11 18:12:00
The rest of the codebecase doesn't comment on anon
Clemens Hammacher
2016/04/12 08:30:48
Done.
| |
| 21 | |
| 22 #define CHECK_CSTREQ(exp, found) \ | |
| 23 do { \ | |
| 24 if (V8_UNLIKELY(strcmp(exp, found) != 0)) { \ | |
| 25 V8_Fatal(__FILE__, __LINE__, \ | |
| 26 "Check failed: (%s) != (%s) ('%s' vs '%s').", #exp, #found, \ | |
| 27 exp, found); \ | |
| 28 } \ | |
| 29 } while (0) | |
|
JF
2016/04/11 18:12:00
This is better because it prevents re-evaluating t
Clemens Hammacher
2016/04/12 08:30:48
Done.
| |
| 30 | |
| 31 void PrintStackTrace(v8::Local<v8::StackTrace> stack) { | |
| 32 printf("Stack Trace (length %d):\n", stack->GetFrameCount()); | |
| 33 for (int i = 0, e = stack->GetFrameCount(); i != e; ++i) { | |
| 34 v8::Local<v8::StackFrame> frame = stack->GetFrame(i); | |
| 35 USE(frame); | |
|
JF
2016/04/11 18:12:00
This isn't necessary? frame is used below.
Clemens Hammacher
2016/04/12 08:30:48
Right, I removed it.
| |
| 36 v8::Local<v8::String> script = frame->GetScriptName(); | |
| 37 v8::Local<v8::String> func = frame->GetFunctionName(); | |
| 38 printf("[%d] (%s) %s:%d:%d\n", i, | |
| 39 script.IsEmpty() ? "<null>" : *v8::String::Utf8Value(script), | |
| 40 func.IsEmpty() ? "<null>" : *v8::String::Utf8Value(func), | |
| 41 frame->GetLineNumber(), frame->GetColumn()); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 template <int N> | |
| 46 void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc, | |
| 47 const char* (&functionNames)[N], | |
| 48 int (&lineNumbers)[N]) { | |
|
JF
2016/04/11 18:12:00
Passing in std::vector would be cleaner than templ
Clemens Hammacher
2016/04/12 08:30:48
Not all buildbots can create std::vector from init
| |
| 49 // check that it's indeed an Error object | |
| 50 CHECK(Object::IsErrorObject(isolate, exc)); | |
| 51 | |
| 52 // extract stack frame from exception | |
| 53 Local<v8::Value> localExc = Utils::ToLocal(exc); | |
| 54 v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc); | |
| 55 PrintStackTrace(stack); | |
| 56 CHECK(!stack.IsEmpty()); | |
| 57 CHECK_EQ(N, stack->GetFrameCount()); | |
| 58 | |
| 59 for (int frameNr = 0; frameNr < N; ++frameNr) { | |
| 60 v8::Local<v8::StackFrame> frame = stack->GetFrame(frameNr); | |
| 61 v8::String::Utf8Value funName(frame->GetFunctionName()); | |
| 62 CHECK_CSTREQ(functionNames[frameNr], *funName); | |
| 63 CHECK_EQ(lineNumbers[frameNr], frame->GetLineNumber()); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 } // anonymous namespace | |
| 68 | |
| 69 // Call from JS to WASM to JS and throw an Error from JS. | |
| 70 TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { | |
| 71 TestSignatures sigs; | |
| 72 TestingModule module; | |
| 73 | |
| 74 WasmFunctionCompiler comp1(sigs.v_v(), &module); | |
| 75 | |
| 76 uint32_t jsThrowingIndex = module.AddJsFunction( | |
| 77 sigs.v_v(), | |
| 78 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); | |
| 79 | |
| 80 BUILD(comp1, WASM_CALL_FUNCTION0(jsThrowingIndex)); | |
| 81 uint32_t wasmIndex = comp1.CompileAndAdd(); | |
| 82 | |
| 83 WasmFunctionCompiler comp2(sigs.v_v(), &module); | |
| 84 BUILD(comp2, WASM_CALL_FUNCTION0(wasmIndex)); | |
| 85 uint32_t wasmIndex2 = comp2.CompileAndAdd(); | |
| 86 | |
| 87 Handle<JSFunction> jsWasmWrapper = module.WrapCode(wasmIndex2); | |
| 88 | |
| 89 Handle<JSFunction> jsTrampoline = Handle<JSFunction>::cast( | |
| 90 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | |
| 91 CompileRun("(function callFn(fn) { fn(); })")))); | |
| 92 | |
| 93 Isolate* isolate = jsWasmWrapper->GetIsolate(); | |
| 94 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | |
| 95 v8::StackTrace::kOverview); | |
| 96 Handle<Object> global(isolate->context()->global_object(), isolate); | |
| 97 MaybeHandle<Object> excMaybe; | |
| 98 Handle<Object> args[] = {jsWasmWrapper}; | |
| 99 MaybeHandle<Object> returnObjMaybe = | |
| 100 Execution::TryCall(isolate, jsTrampoline, global, 1, args, &excMaybe); | |
| 101 CHECK(returnObjMaybe.is_null()); | |
| 102 | |
| 103 const char* funcNames[] = {"a", "js", "<WASM>", "<WASM>", "callFn"}; | |
| 104 // line number is 1-based, with 0 == kNoLineNumberInfo | |
| 105 int lineNrs[] = {3, 4, 0, 0, 1}; | |
| 106 CheckExceptionInfos(isolate, excMaybe.ToHandleChecked(), funcNames, lineNrs); | |
| 107 } | |
| OLD | NEW |