Commit 0655c459 authored by yangguo's avatar yangguo Committed by Commit bot

[serializer] add test case for unknown external references.

Unknown external references must trigger assertion failure.

Review-Url: https://codereview.chromium.org/2428463002
Cr-Commit-Position: refs/heads/master@{#40391}
parent b275457e
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "src/ic/stub-cache.h" #include "src/ic/stub-cache.h"
#include "src/list-inl.h" #include "src/list-inl.h"
#if defined(DEBUG) && defined(V8_OS_LINUX)
#include <execinfo.h>
#endif // DEBUG && V8_OS_LINUX
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -33,7 +37,14 @@ uint32_t ExternalReferenceEncoder::Encode(Address address) const { ...@@ -33,7 +37,14 @@ uint32_t ExternalReferenceEncoder::Encode(Address address) const {
DCHECK_NOT_NULL(address); DCHECK_NOT_NULL(address);
base::HashMap::Entry* entry = base::HashMap::Entry* entry =
const_cast<base::HashMap*>(map_)->Lookup(address, Hash(address)); const_cast<base::HashMap*>(map_)->Lookup(address, Hash(address));
DCHECK_NOT_NULL(entry); if (entry == nullptr) {
void* function_addr = address;
v8::base::OS::PrintError("Unknown external reference %p.\n", function_addr);
#if defined(DEBUG) && defined(V8_OS_LINUX)
v8::base::OS::PrintError("%s\n", backtrace_symbols(&function_addr, 1)[0]);
#endif // DEBUG && V8_OS_LINUX
v8::base::OS::Abort();
}
return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
} }
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
[ALWAYS, { [ALWAYS, {
# All tests prefixed with 'Bug' are expected to fail. # All tests prefixed with 'Bug' are expected to fail.
'test-api/Bug*': [FAIL], 'test-api/Bug*': [FAIL],
'test-serialize/Bug*': [FAIL],
############################################################################## ##############################################################################
...@@ -90,6 +89,9 @@ ...@@ -90,6 +89,9 @@
# BUG(3742). # BUG(3742).
'test-mark-compact/MarkCompactCollector': [PASS, ['arch==arm', NO_VARIANTS]], 'test-mark-compact/MarkCompactCollector': [PASS, ['arch==arm', NO_VARIANTS]],
# Test that serialization with unknown external reference fails.
'test-serialize/SnapshotCreatorUnknownExternalReferences': [FAIL],
############################################################################ ############################################################################
# Slow tests. # Slow tests.
'test-api/Threading1': [PASS, ['mode == debug', SLOW]], 'test-api/Threading1': [PASS, ['mode == debug', SLOW]],
......
...@@ -2010,12 +2010,11 @@ TEST(SnapshotCreatorMultipleContexts) { ...@@ -2010,12 +2010,11 @@ TEST(SnapshotCreatorMultipleContexts) {
delete[] blob.data; delete[] blob.data;
} }
static void SerializedCallback( void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(v8_num(42)); args.GetReturnValue().Set(v8_num(42));
} }
static void SerializedCallbackReplacement( void SerializedCallbackReplacement(
const v8::FunctionCallbackInfo<v8::Value>& args) { const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(v8_num(1337)); args.GetReturnValue().Set(v8_num(1337));
} }
...@@ -2086,6 +2085,30 @@ TEST(SnapshotCreatorExternalReferences) { ...@@ -2086,6 +2085,30 @@ TEST(SnapshotCreatorExternalReferences) {
delete[] blob.data; delete[] blob.data;
} }
TEST(SnapshotCreatorUnknownExternalReferences) {
DisableTurbofan();
v8::SnapshotCreator creator;
v8::Isolate* isolate = creator.GetIsolate();
{
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::Local<v8::FunctionTemplate> callback =
v8::FunctionTemplate::New(isolate, SerializedCallback);
v8::Local<v8::Value> function =
callback->GetFunction(context).ToLocalChecked();
CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust());
ExpectInt32("f()", 42);
CHECK_EQ(0, creator.AddContext(context));
}
v8::StartupData blob =
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
delete[] blob.data;
}
TEST(SnapshotCreatorTemplates) { TEST(SnapshotCreatorTemplates) {
DisableTurbofan(); DisableTurbofan();
v8::StartupData blob; v8::StartupData blob;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment