summaryrefslogtreecommitdiff
path: root/chromium/gin
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-05 17:15:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-11 07:47:18 +0000
commit7324afb043a0b1e623d8e8eb906cdc53bdeb4685 (patch)
treea3fe2d74ea9c9e142c390dac4ca0e219382ace46 /chromium/gin
parent6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (diff)
downloadqtwebengine-chromium-7324afb043a0b1e623d8e8eb906cdc53bdeb4685.tar.gz
BASELINE: Update Chromium to 58.0.3029.54
Change-Id: I67f57065a7afdc8e4614adb5c0230281428df4d1 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/gin')
-rw-r--r--chromium/gin/BUILD.gn57
-rwxr-xr-xchromium/gin/fingerprint/fingerprint_v8_snapshot.py86
-rw-r--r--chromium/gin/isolate_holder.cc7
-rw-r--r--chromium/gin/public/isolate_holder.h9
-rw-r--r--chromium/gin/v8_initializer.cc76
-rw-r--r--chromium/gin/v8_platform.cc20
-rw-r--r--chromium/gin/v8_platform_unittest.cc62
7 files changed, 123 insertions, 194 deletions
diff --git a/chromium/gin/BUILD.gn b/chromium/gin/BUILD.gn
index 72d0125d92c..6ad0eac4e6f 100644
--- a/chromium/gin/BUILD.gn
+++ b/chromium/gin/BUILD.gn
@@ -5,6 +5,24 @@
import("//testing/test.gni")
import("//v8/gni/v8.gni")
+# This is depended upon from the browser DLL on Windows, where V8 is not used,
+# but features are enabled. This cannot depend on V8.
+source_set("gin_features") {
+ sources = [
+ "gin_export.h",
+ "gin_features.cc",
+ "public/gin_features.h",
+ ]
+
+ defines = [ "GIN_IMPLEMENTATION" ]
+
+ deps = [
+ "//base",
+ ]
+
+ assert_no_deps = [ "//v8" ]
+}
+
component("gin") {
sources = [
"arguments.cc",
@@ -21,7 +39,6 @@ component("gin") {
"function_template.cc",
"function_template.h",
"gin_export.h",
- "gin_features.cc",
"handle.h",
"interceptor.cc",
"interceptor.h",
@@ -46,7 +63,6 @@ component("gin") {
"public/context_holder.h",
"public/debug.h",
"public/gin_embedders.h",
- "public/gin_features.h",
"public/isolate_holder.h",
"public/v8_idle_task_runner.h",
"public/v8_platform.h",
@@ -83,14 +99,10 @@ component("gin") {
"//v8",
]
deps = [
+ ":gin_features",
"//base/third_party/dynamic_annotations",
"//crypto",
]
- if (v8_use_external_startup_data && is_win) {
- public_deps += [ ":gin_v8_snapshot_fingerprint" ]
- sources += [ "$target_gen_dir/v8_snapshot_fingerprint.cc" ]
- defines += [ "V8_VERIFY_EXTERNAL_STARTUP_DATA" ]
- }
if (is_mac) {
libs = [ "CoreFoundation.framework" ]
@@ -99,36 +111,6 @@ component("gin") {
configs += [ "//v8:external_startup_data" ]
}
-if (v8_use_external_startup_data) {
- action("gin_v8_snapshot_fingerprint") {
- script = "//gin/fingerprint/fingerprint_v8_snapshot.py"
-
- snapshot_file = "$root_out_dir/snapshot_blob.bin"
- natives_file = "$root_out_dir/natives_blob.bin"
- output_file = "$target_gen_dir/v8_snapshot_fingerprint.cc"
-
- args = [
- "--snapshot_file",
- rebase_path(snapshot_file, root_build_dir),
- "--natives_file",
- rebase_path(natives_file, root_build_dir),
- "--output_file",
- rebase_path(output_file, root_build_dir),
- ]
- inputs = [
- snapshot_file,
- natives_file,
- ]
- outputs = [
- output_file,
- ]
-
- deps = [
- "//v8",
- ]
- }
-}
-
executable("gin_shell") {
sources = [
"shell/gin_main.cc",
@@ -187,6 +169,7 @@ test("gin_unittests") {
"test/run_all_unittests.cc",
"test/run_js_tests.cc",
"v8_isolate_memory_dump_provider_unittest.cc",
+ "v8_platform_unittest.cc",
"wrappable_unittest.cc",
]
diff --git a/chromium/gin/fingerprint/fingerprint_v8_snapshot.py b/chromium/gin/fingerprint/fingerprint_v8_snapshot.py
deleted file mode 100755
index d1f70923335..00000000000
--- a/chromium/gin/fingerprint/fingerprint_v8_snapshot.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2015 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""Fingerprints the V8 snapshot blob files.
-
-Constructs a SHA256 fingerprint of the V8 natives and snapshot blob files and
-creates a .cc file which includes these fingerprint as variables.
-"""
-
-import hashlib
-import optparse
-import os
-import sys
-
-_HEADER = """// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// This file was generated by fingerprint_v8_snapshot.py.
-
-namespace gin {
-"""
-
-_FOOTER = """
-} // namespace gin
-"""
-
-
-def FingerprintFile(file_path):
- input_file = open(file_path, 'rb')
- sha256 = hashlib.sha256()
- while True:
- block = input_file.read(sha256.block_size)
- if not block:
- break
- sha256.update(block)
- return sha256.digest()
-
-
-def WriteFingerprint(output_file, variable_name, fingerprint):
- output_file.write('\nextern const unsigned char %s[] = { ' % variable_name)
- for byte in fingerprint:
- output_file.write(str(ord(byte)) + ', ')
- output_file.write('};\n')
-
-
-def WriteOutputFile(natives_fingerprint,
- snapshot_fingerprint,
- output_file_path):
- output_dir_path = os.path.dirname(output_file_path)
- if not os.path.exists(output_dir_path):
- os.makedirs(output_dir_path)
- output_file = open(output_file_path, 'w')
-
- output_file.write(_HEADER)
- WriteFingerprint(output_file, 'g_natives_fingerprint', natives_fingerprint)
- output_file.write('\n')
- WriteFingerprint(output_file, 'g_snapshot_fingerprint', snapshot_fingerprint)
- output_file.write(_FOOTER)
-
-
-def main():
- parser = optparse.OptionParser()
-
- parser.add_option('--snapshot_file',
- help='The input V8 snapshot blob file path.')
- parser.add_option('--natives_file',
- help='The input V8 natives blob file path.')
- parser.add_option('--output_file',
- help='The path for the output cc file which will be write.')
-
- options, _ = parser.parse_args()
-
- natives_fingerprint = FingerprintFile(options.natives_file)
- snapshot_fingerprint = FingerprintFile(options.snapshot_file)
- WriteOutputFile(
- natives_fingerprint, snapshot_fingerprint, options.output_file)
-
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main())
diff --git a/chromium/gin/isolate_holder.cc b/chromium/gin/isolate_holder.cc
index e38190c4285..caea27e7a56 100644
--- a/chromium/gin/isolate_holder.cc
+++ b/chromium/gin/isolate_holder.cc
@@ -34,6 +34,12 @@ IsolateHolder::IsolateHolder(
IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode)
+ : IsolateHolder(std::move(task_runner), access_mode, kAllowAtomicsWait) {}
+
+IsolateHolder::IsolateHolder(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ AccessMode access_mode,
+ AllowAtomicsWaitMode atomics_wait_mode)
: access_mode_(access_mode) {
v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
@@ -43,6 +49,7 @@ IsolateHolder::IsolateHolder(
params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
base::SysInfo::AmountOfVirtualMemory());
params.array_buffer_allocator = allocator;
+ params.allow_atomics_wait = atomics_wait_mode == kAllowAtomicsWait;
isolate_ = v8::Isolate::New(params);
isolate_data_.reset(
new PerIsolateData(isolate_, allocator, access_mode, task_runner));
diff --git a/chromium/gin/public/isolate_holder.h b/chromium/gin/public/isolate_holder.h
index 62b87108580..0d9cb3b39ef 100644
--- a/chromium/gin/public/isolate_holder.h
+++ b/chromium/gin/public/isolate_holder.h
@@ -41,6 +41,12 @@ class GIN_EXPORT IsolateHolder {
kUseLocker
};
+ // Whether Atomics.wait can be called on this isolate.
+ enum AllowAtomicsWaitMode {
+ kDisallowAtomicsWait,
+ kAllowAtomicsWait
+ };
+
// Indicates whether V8 works with stable or experimental v8 extras.
enum V8ExtrasMode {
kStableV8Extras,
@@ -51,6 +57,9 @@ class GIN_EXPORT IsolateHolder {
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode);
+ IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ AccessMode access_mode,
+ AllowAtomicsWaitMode atomics_wait_mode);
~IsolateHolder();
// Should be invoked once before creating IsolateHolder instances to
diff --git a/chromium/gin/v8_initializer.cc b/chromium/gin/v8_initializer.cc
index 9abea43866b..4131f0481e9 100644
--- a/chromium/gin/v8_initializer.cc
+++ b/chromium/gin/v8_initializer.cc
@@ -191,36 +191,6 @@ static const OpenedFileMap::mapped_type OpenFileIfNecessary(
return opened;
}
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
-bool VerifyV8StartupFile(base::MemoryMappedFile** file,
- const unsigned char* fingerprint) {
- unsigned char output[crypto::kSHA256Length];
- crypto::SHA256HashString(
- base::StringPiece(reinterpret_cast<const char*>((*file)->data()),
- (*file)->length()),
- output, sizeof(output));
- if (!memcmp(fingerprint, output, sizeof(output))) {
- return true;
- }
-
- // TODO(oth): Remove this temporary diagnostics for http://crbug.com/501799
- uint64_t input[sizeof(output)];
- memcpy(input, fingerprint, sizeof(input));
-
- base::debug::Alias(output);
- base::debug::Alias(input);
-
- const uint64_t* o64 = reinterpret_cast<const uint64_t*>(output);
- const uint64_t* f64 = reinterpret_cast<const uint64_t*>(fingerprint);
- LOG(FATAL) << "Natives length " << (*file)->length()
- << " H(computed) " << o64[0] << o64[1] << o64[2] << o64[3]
- << " H(expected) " << f64[0] << f64[1] << f64[2] << f64[3];
-
- delete *file;
- *file = NULL;
- return false;
-}
-#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
#endif // V8_USE_EXTERNAL_STARTUP_DATA
bool GenerateEntropy(unsigned char* buffer, size_t amount) {
@@ -231,47 +201,37 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) {
} // namespace
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
-// Defined in gen/gin/v8_snapshot_fingerprint.cc
-extern const unsigned char g_natives_fingerprint[];
-extern const unsigned char g_snapshot_fingerprint[];
-#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
+
+namespace {
enum LoadV8FileResult {
V8_LOAD_SUCCESS = 0,
V8_LOAD_FAILED_OPEN,
V8_LOAD_FAILED_MAP,
- V8_LOAD_FAILED_VERIFY,
+ V8_LOAD_FAILED_VERIFY, // Deprecated.
V8_LOAD_MAX_VALUE
};
-static LoadV8FileResult MapVerify(const OpenedFileMap::mapped_type& file_region,
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- const unsigned char* fingerprint,
-#endif
- base::MemoryMappedFile** mmapped_file_out) {
+static LoadV8FileResult MapOpenedFile(
+ const OpenedFileMap::mapped_type& file_region,
+ base::MemoryMappedFile** mmapped_file_out) {
if (file_region.first == base::kInvalidPlatformFile)
return V8_LOAD_FAILED_OPEN;
if (!MapV8File(file_region.first, file_region.second, mmapped_file_out))
return V8_LOAD_FAILED_MAP;
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- if (!VerifyV8StartupFile(mmapped_file_out, fingerprint))
- return V8_LOAD_FAILED_VERIFY;
-#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
return V8_LOAD_SUCCESS;
}
+} // namespace
+
// static
void V8Initializer::LoadV8Snapshot() {
if (g_mapped_snapshot)
return;
OpenFileIfNecessary(kSnapshotFileName);
- LoadV8FileResult result = MapVerify(GetOpenedFile(kSnapshotFileName),
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- g_snapshot_fingerprint,
-#endif
- &g_mapped_snapshot);
+ LoadV8FileResult result = MapOpenedFile(GetOpenedFile(kSnapshotFileName),
+ &g_mapped_snapshot);
// V8 can't start up without the source of the natives, but it can
// start up (slower) without the snapshot.
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result,
@@ -283,11 +243,8 @@ void V8Initializer::LoadV8Natives() {
return;
OpenFileIfNecessary(kNativesFileName);
- LoadV8FileResult result = MapVerify(GetOpenedFile(kNativesFileName),
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- g_natives_fingerprint,
-#endif
- &g_mapped_natives);
+ LoadV8FileResult result = MapOpenedFile(GetOpenedFile(kNativesFileName),
+ &g_mapped_natives);
if (result != V8_LOAD_SUCCESS) {
LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is "
<< static_cast<int>(result);
@@ -314,10 +271,6 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf,
LoadV8FileResult result = V8_LOAD_SUCCESS;
if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot))
result = V8_LOAD_FAILED_MAP;
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint))
- result = V8_LOAD_FAILED_VERIFY;
-#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
if (result == V8_LOAD_SUCCESS) {
g_opened_files.Get()[kSnapshotFileName] =
std::make_pair(snapshot_pf, snapshot_region);
@@ -345,11 +298,6 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) {
LOG(FATAL) << "Couldn't mmap v8 natives data file";
}
-#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
- if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) {
- LOG(FATAL) << "Couldn't verify contents of v8 natives data file";
- }
-#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
g_opened_files.Get()[kNativesFileName] =
std::make_pair(natives_pf, natives_region);
}
diff --git a/chromium/gin/v8_platform.cc b/chromium/gin/v8_platform.cc
index 6e5491bff11..276dd77c9d6 100644
--- a/chromium/gin/v8_platform.cc
+++ b/chromium/gin/v8_platform.cc
@@ -204,25 +204,31 @@ class EnabledStateObserverImpl final
void OnTraceLogEnabled() final {
base::AutoLock lock(mutex_);
- for (auto o : observers_) {
+ for (auto* o : observers_) {
o->OnTraceEnabled();
}
}
void OnTraceLogDisabled() final {
base::AutoLock lock(mutex_);
- for (auto o : observers_) {
+ for (auto* o : observers_) {
o->OnTraceDisabled();
}
}
void AddObserver(v8::Platform::TraceStateObserver* observer) {
- base::AutoLock lock(mutex_);
- DCHECK(!observers_.count(observer));
- observers_.insert(observer);
- if (observers_.size() == 1) {
- base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
+ {
+ base::AutoLock lock(mutex_);
+ DCHECK(!observers_.count(observer));
+ if (observers_.empty()) {
+ base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(
+ this);
+ }
+ observers_.insert(observer);
}
+ // Fire the observer if recording is already in progress.
+ if (base::trace_event::TraceLog::GetInstance()->IsEnabled())
+ observer->OnTraceEnabled();
}
void RemoveObserver(v8::Platform::TraceStateObserver* observer) {
diff --git a/chromium/gin/v8_platform_unittest.cc b/chromium/gin/v8_platform_unittest.cc
new file mode 100644
index 00000000000..52d58624003
--- /dev/null
+++ b/chromium/gin/v8_platform_unittest.cc
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gin/public/v8_platform.h"
+
+#include "base/trace_event/trace_event.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class TestTraceStateObserver
+ : public NON_EXPORTED_BASE(v8::Platform::TraceStateObserver) {
+ public:
+ void OnTraceEnabled() final { ++enabled_; }
+ void OnTraceDisabled() final { ++disabled_; }
+ int Enabled() { return enabled_; }
+ int Disabled() { return disabled_; }
+
+ private:
+ int enabled_ = 0;
+ int disabled_ = 0;
+};
+
+namespace gin {
+
+TEST(V8PlatformTest, TraceStateObserverAPI) {
+ TestTraceStateObserver* test_observer = new TestTraceStateObserver();
+ ASSERT_EQ(0, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+
+ V8Platform::Get()->AddTraceStateObserver(test_observer);
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+ base::trace_event::TraceLog::GetInstance()->SetDisabled();
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(1, test_observer->Disabled());
+
+ V8Platform::Get()->RemoveTraceStateObserver(test_observer);
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ base::trace_event::TraceLog::GetInstance()->SetDisabled();
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(1, test_observer->Disabled());
+}
+
+TEST(V8PlatformTest, TraceStateObserverFired) {
+ TestTraceStateObserver* test_observer = new TestTraceStateObserver();
+ ASSERT_EQ(0, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ V8Platform::Get()->AddTraceStateObserver(test_observer);
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+}
+
+} // namespace gin