Commit c1d39129 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

cppgc: Fix hello world

The hello world sample needs to initialize V8's default platform in case
it is not built as stand-alone example.

Bug: v8:12427
Change-Id: I78b68fbed2c2a25b0ff03675beb94dfc5b9b4135
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3412088Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78756}
parent c0c91295
......@@ -63,6 +63,8 @@ class V8_EXPORT DefaultPlatform : public Platform {
return v8_platform_->GetTracingController();
}
v8::Platform* GetV8Platform() const { return v8_platform_.get(); }
protected:
static constexpr v8::Isolate* kNoIsolate = nullptr;
......
......@@ -2,17 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cppgc/allocation.h>
#include <cppgc/default-platform.h>
#include <cppgc/garbage-collected.h>
#include <cppgc/heap.h>
#include <cppgc/member.h>
#include <cppgc/visitor.h>
#include <iostream>
#include <memory>
#include <string>
#include "include/cppgc/allocation.h"
#include "include/cppgc/default-platform.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/heap.h"
#include "include/cppgc/member.h"
#include "include/cppgc/visitor.h"
#if !CPPGC_IS_STANDALONE
#include "include/v8-initialization.h"
#endif // !CPPGC_IS_STANDALONE
/**
* This sample program shows how to set up a stand-alone cppgc heap.
*/
......@@ -45,6 +49,12 @@ int main(int argc, char* argv[]) {
// Create a default platform that is used by cppgc::Heap for execution and
// backend allocation.
auto cppgc_platform = std::make_shared<cppgc::DefaultPlatform>();
#if !CPPGC_IS_STANDALONE
// When initializing a stand-alone cppgc heap in a regular V8 build, the
// internal V8 platform will be reused. Reusing the V8 platform requires
// initializing it properly.
v8::V8::InitializePlatform(cppgc_platform->GetV8Platform());
#endif // !CPPGC_IS_STANDALONE
// Initialize the process. This must happen before any cppgc::Heap::Create()
// calls.
cppgc::DefaultPlatform::InitializeProcess(cppgc_platform.get());
......
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