这个环节比较简单,直接上代码了
main.cpp
// Copyright the V8 project 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 <stdio.h>#include <stdlib.h>#include <string.h>#include "include/libplatform/libplatform.h"#include "include/v8.h"using namespace std;using namespace v8;const std::string fileName = "file.js";// Reads a file into a v8 string.MaybeLocal<String> ReadFile( Isolate* isolate, const string& name ) {FILE* file = fopen( name.c_str(), "rb" );if ( file == NULL ) return MaybeLocal<String>();fseek( file, 0, SEEK_END );size_t size = ftell( file );rewind( file );std::unique_ptr<char> chars( new char[size + 1] );chars.get()[size] = \ ;for ( size_t i = 0; i < size;) {