WebAssembly: support name section
JSTests:
https://bugs.webkit.org/show_bug.cgi?id=171263
Reviewed by Keith Miller.
* wasm/function-tests/nameSection.js: Added.
(const.compile):
* wasm/function-tests/nameSection.wasm: Added.
* wasm/function-tests/stack-trace.js: Update format
Source/JavaScriptCore:
https://bugs.webkit.org/show_bug.cgi?id=171263
Reviewed by Keith Miller.
The name section is an optional custom section in the WebAssembly
spec. At least when debugging, developers expect to be able to use
this section to obtain intelligible stack traces, otherwise we
just number the wasm functions which is somewhat painful.
This patch parses this section, dropping its content eagerly on
error, and if there is a name section then backtraces use their
value instead of numbers. Otherwise we stick to numbers as before.
Note that the format of name sections changed in mid-February:
https://github.com/WebAssembly/design/pull/984
And binaryen was only updated in early March:
https://github.com/WebAssembly/binaryen/pull/933
* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* interpreter/Interpreter.cpp:
(JSC::GetStackTraceFunctor::operator()):
* interpreter/StackVisitor.cpp:
(JSC::StackVisitor::readNonInlinedFrame):
(JSC::StackVisitor::Frame::functionName):
* interpreter/StackVisitor.h:
(JSC::StackVisitor::Frame::wasmFunctionIndexOrName):
* runtime/StackFrame.cpp:
(JSC::StackFrame::functionName):
* runtime/StackFrame.h:
(JSC::StackFrame::StackFrame):
(JSC::StackFrame::wasm):
* wasm/WasmBBQPlanInlines.h:
(JSC::Wasm::BBQPlan::initializeCallees):
* wasm/WasmCallee.cpp:
(JSC::Wasm::Callee::Callee):
* wasm/WasmCallee.h:
(JSC::Wasm::Callee::create):
(JSC::Wasm::Callee::indexOrName):
* wasm/WasmFormat.cpp:
(JSC::Wasm::makeString):
* wasm/WasmFormat.h:
(JSC::Wasm::isValidExternalKind):
(JSC::Wasm::isValidNameType):
(JSC::Wasm::NameSection::get):
* wasm/WasmIndexOrName.cpp: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
(JSC::Wasm::IndexOrName::IndexOrName):
(JSC::Wasm::makeString):
* wasm/WasmIndexOrName.h: Copied from Source/JavaScriptCore/wasm/WasmFormat.cpp.
* wasm/WasmModuleInformation.h:
* wasm/WasmModuleParser.cpp:
* wasm/WasmName.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
* wasm/WasmNameSectionParser.cpp: Added.
* wasm/WasmNameSectionParser.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
(JSC::Wasm::NameSectionParser::NameSectionParser):
* wasm/WasmOMGPlan.cpp:
(JSC::Wasm::OMGPlan::work):
* wasm/WasmParser.h:
(JSC::Wasm::Parser<SuccessType>::consumeUTF8String):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216597 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/interpreter/StackVisitor.cpp b/Source/JavaScriptCore/interpreter/StackVisitor.cpp
index 52eafc9..1d64d6e 100644
--- a/Source/JavaScriptCore/interpreter/StackVisitor.cpp
+++ b/Source/JavaScriptCore/interpreter/StackVisitor.cpp
@@ -32,6 +32,7 @@
#include "Interpreter.h"
#include "JSCInlines.h"
#include "WasmCallee.h"
+#include "WasmIndexOrName.h"
#include <wtf/text/StringBuilder.h>
namespace JSC {
@@ -166,7 +167,7 @@
#if ENABLE(WEBASSEMBLY)
CalleeBits bits = callFrame->callee();
if (bits.isWasm())
- m_frame.m_wasmFunctionIndex = bits.asWasmCallee()->index();
+ m_frame.m_wasmFunctionIndexOrName = bits.asWasmCallee()->indexOrName();
#endif
} else {
m_frame.m_codeBlock = callFrame->codeBlock();
@@ -283,10 +284,10 @@
switch (codeType()) {
case CodeType::Wasm:
- if (m_wasmFunctionIndex)
- traceLine = makeString("wasm function index: ", String::number(*m_wasmFunctionIndex));
+ if (m_wasmFunctionIndexOrName.isEmpty())
+ traceLine = makeString("wasm function");
else
- traceLine = ASCIILiteral("wasm function");
+ traceLine = makeString("wasm function: ", makeString(m_wasmFunctionIndexOrName));
break;
case CodeType::Eval:
traceLine = ASCIILiteral("eval code");