1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "frameworks/bridge/common/utils/v8/v8_helper.h" 17 18 extern const char _binary_v8_startup_snapshot_bin_start[]; 19 extern const char _binary_v8_startup_snapshot_bin_end[]; 20 21 namespace OHOS::Ace::Framework { 22 V8Helper()23V8Helper::V8Helper() 24 { 25 static v8::StartupData snapshotBlob = { 26 .data = _binary_v8_startup_snapshot_bin_start, 27 .raw_size = _binary_v8_startup_snapshot_bin_end - _binary_v8_startup_snapshot_bin_start, 28 }; 29 v8::V8::SetSnapshotDataBlob(&snapshotBlob); 30 platform_ = v8::platform::NewDefaultPlatform(); 31 v8::V8::InitializePlatform(platform_.get()); 32 v8::V8::Initialize(); 33 } 34 ~V8Helper()35V8Helper::~V8Helper() 36 { 37 v8::V8::Dispose(); 38 v8::V8::ShutdownPlatform(); 39 } 40 GetPlatform()41std::unique_ptr<v8::Platform>& V8Helper::GetPlatform() 42 { 43 static V8Helper v8Helper; 44 return v8Helper.platform_; 45 } 46 47 } // namespace OHOS::Ace::Framework 48