Last active
November 2, 2024 02:28
-
-
Save zsxsoft/95647a309642074df0194d39f0dbce94 to your computer and use it in GitHub Desktop.
v8-bytecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const w = fs.readFileSync('bytecode.txt', 'utf-8') | |
const p = w.split('\n').map(p => p.split(',').map(p => p.trim())) | |
//const shell = fs.readFileSync('nwjs-sdk-v0.30.5-linux-x64/1.out') | |
const shell = fs.readFileSync('nwjs/linux64/kernel.bin') | |
const fuck = (start) => { | |
const areas = [] | |
let index = 0 | |
while (true) { | |
let w = shell.indexOf(Buffer.from([0x00, 0x40, 0x02]), index + 1) | |
index = w | |
let p = shell.indexOf(Buffer.from([0xa2, 0x00]), index) | |
areas.push(shell.slice(w + 6, p + 1)) | |
if (w <= 0) break | |
} | |
return areas.map(area => { | |
let status = 0 | |
let currentCode = [] | |
let data = [] | |
let isInRegList = 0 | |
let listData = [] | |
let j = 0 | |
let realLength = 0 | |
let index | |
const ret = [] | |
const reset = () => { | |
status = 0 | |
ret.push(data) | |
data = [] | |
isInRegList = 0 | |
realLength = 0 | |
} | |
for (let i = 0; i < area.length; i++) { | |
let l = area[i] | |
if (status === 0) { | |
console.log(p[l]) | |
currentCode = p[l] | |
data.push(start + i) | |
data.push(currentCode[0]) | |
status = 1 | |
j = 0 | |
realLength = currentCode.length | |
if (currentCode.length === 2) { | |
reset() | |
} | |
if (currentCode[0] === 'CallRuntime') { | |
j -= 1 | |
} | |
} else if (status === 1) { | |
j++ | |
if (currentCode[j + 1] === 'OperandType::kRegList') { | |
// do fucking nothing | |
} else if (currentCode[j] === 'OperandType::kRegList') { | |
data.push("list(r" + (0xfb - area[i - 1]) + " to " + l + ")") | |
data.push("") | |
} else if (currentCode[j + 1] === 'OperandType::kRuntimeId') { | |
data.push("runtime=" + l) | |
j++ | |
j++ | |
data.push("list(r" + (0xfb - area[i+1]) + " to " + area[i+2] + ")") | |
i++ | |
i++ | |
reset() | |
continue | |
} else { | |
if (l <= 0xfb && l >= 0xe0) { | |
data.push("r" + (0xfb - l)) | |
} else { | |
data.push(l) | |
} | |
if (data.length >= realLength) { | |
reset() | |
} | |
} | |
} | |
} | |
return ret | |
}) | |
} | |
const r = fuck(0) | |
console.dir(r) | |
//console.log(JSON.stringify(r)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Wide, AccumulatorUse::kNone | |
ExtraWide, AccumulatorUse::kNone | |
DebugBreakWide, AccumulatorUse::kReadWrite | |
DebugBreakExtraWide, AccumulatorUse::kReadWrite | |
DebugBreak0, AccumulatorUse::kReadWrite | |
DebugBreak1, AccumulatorUse::kReadWrite, OperandType::kReg | |
DebugBreak2, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kReg | |
DebugBreak3, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kReg, OperandType::kReg | |
DebugBreak4, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kReg, OperandType::kReg, OperandType::kReg | |
DebugBreak5, AccumulatorUse::kReadWrite, OperandType::kRuntimeId, OperandType::kReg, OperandType::kReg | |
DebugBreak6, AccumulatorUse::kReadWrite, OperandType::kRuntimeId, OperandType::kReg, OperandType::kReg, OperandType::kReg | |
LdaZero, AccumulatorUse::kWrite | |
LdaSmi, AccumulatorUse::kWrite, OperandType::kImm | |
LdaUndefined, AccumulatorUse::kWrite | |
LdaNull, AccumulatorUse::kWrite | |
LdaTheHole, AccumulatorUse::kWrite | |
LdaTrue, AccumulatorUse::kWrite | |
LdaFalse, AccumulatorUse::kWrite | |
LdaConstant, AccumulatorUse::kWrite, OperandType::kIdx | |
LdaGlobal, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx | |
LdaGlobalInsideTypeof, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx | |
StaGlobal, AccumulatorUse::kRead, OperandType::kIdx, OperandType::kIdx | |
PushContext, AccumulatorUse::kRead, OperandType::kRegOut | |
PopContext, AccumulatorUse::kNone, OperandType::kReg | |
LdaContextSlot, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kIdx, OperandType::kUImm | |
LdaImmutableContextSlot, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kIdx, OperandType::kUImm | |
LdaCurrentContextSlot, AccumulatorUse::kWrite, OperandType::kIdx | |
LdaImmutableCurrentContextSlot, AccumulatorUse::kWrite, OperandType::kIdx | |
StaContextSlot, AccumulatorUse::kRead, OperandType::kReg, OperandType::kIdx, OperandType::kUImm | |
StaCurrentContextSlot, AccumulatorUse::kRead, OperandType::kIdx | |
LdaLookupSlot, AccumulatorUse::kWrite, OperandType::kIdx | |
LdaLookupContextSlot, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kUImm | |
LdaLookupGlobalSlot, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kUImm | |
LdaLookupSlotInsideTypeof, AccumulatorUse::kWrite, OperandType::kIdx | |
LdaLookupContextSlotInsideTypeof, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kUImm | |
LdaLookupGlobalSlotInsideTypeof, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kUImm | |
StaLookupSlot, AccumulatorUse::kReadWrite, OperandType::kIdx, OperandType::kFlag8 | |
Ldar, AccumulatorUse::kWrite, OperandType::kReg | |
Star, AccumulatorUse::kRead, OperandType::kRegOut | |
Mov, AccumulatorUse::kNone, OperandType::kReg, OperandType::kRegOut | |
LdaNamedProperty, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kIdx, OperandType::kIdx | |
LdaKeyedProperty, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
LdaModuleVariable, AccumulatorUse::kWrite, OperandType::kImm, OperandType::kUImm | |
StaModuleVariable, AccumulatorUse::kRead, OperandType::kImm, OperandType::kUImm | |
StaNamedProperty, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx, OperandType::kIdx | |
StaNamedOwnProperty, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx, OperandType::kIdx | |
StaKeyedProperty, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
StaDataPropertyInLiteral, AccumulatorUse::kRead, OperandType::kReg, OperandType::kReg, OperandType::kFlag8, OperandType::kIdx | |
CollectTypeProfile, AccumulatorUse::kRead, OperandType::kImm | |
Add, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
Sub, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
Mul, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
Div, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
Mod, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
Exp, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
BitwiseOr, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
BitwiseXor, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
BitwiseAnd, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
ShiftLeft, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
ShiftRight, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
ShiftRightLogical, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
AddSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
SubSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
MulSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
DivSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
ModSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
ExpSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
BitwiseOrSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
BitwiseXorSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
BitwiseAndSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
ShiftLeftSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
ShiftRightSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
ShiftRightLogicalSmi, AccumulatorUse::kReadWrite, OperandType::kImm, OperandType::kIdx | |
Inc, AccumulatorUse::kReadWrite, OperandType::kIdx | |
Dec, AccumulatorUse::kReadWrite, OperandType::kIdx | |
Negate, AccumulatorUse::kReadWrite, OperandType::kIdx | |
BitwiseNot, AccumulatorUse::kReadWrite, OperandType::kIdx | |
ToBooleanLogicalNot, AccumulatorUse::kReadWrite | |
LogicalNot, AccumulatorUse::kReadWrite | |
TypeOf, AccumulatorUse::kReadWrite | |
DeletePropertyStrict, AccumulatorUse::kReadWrite, OperandType::kReg | |
DeletePropertySloppy, AccumulatorUse::kReadWrite, OperandType::kReg | |
GetSuperConstructor, AccumulatorUse::kRead, OperandType::kRegOut | |
CallAnyReceiver, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
CallProperty, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
CallProperty0, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
CallProperty1, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
CallProperty2, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
CallUndefinedReceiver, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
CallUndefinedReceiver0, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kIdx | |
CallUndefinedReceiver1, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
CallUndefinedReceiver2, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kReg, OperandType::kIdx | |
CallWithSpread, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
CallRuntime, AccumulatorUse::kWrite, OperandType::kRuntimeId, OperandType::kRegList, OperandType::kRegCount | |
CallRuntimeForPair, AccumulatorUse::kNone, OperandType::kRuntimeId, OperandType::kRegList, OperandType::kRegCount, OperandType::kRegOutPair | |
CallJSRuntime, AccumulatorUse::kWrite, OperandType::kNativeContextIndex, OperandType::kRegList, OperandType::kRegCount | |
InvokeIntrinsic, AccumulatorUse::kWrite, OperandType::kIntrinsicId, OperandType::kRegList, OperandType::kRegCount | |
Construct, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
ConstructWithSpread, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kIdx | |
TestEqual, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestEqualStrict, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestLessThan, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestGreaterThan, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestLessThanOrEqual, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestGreaterThanOrEqual, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestEqualStrictNoFeedback, AccumulatorUse::kReadWrite, OperandType::kReg | |
TestInstanceOf, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
TestIn, AccumulatorUse::kReadWrite, OperandType::kReg | |
TestUndetectable, AccumulatorUse::kReadWrite | |
TestNull, AccumulatorUse::kReadWrite | |
TestUndefined, AccumulatorUse::kReadWrite | |
TestTypeOf, AccumulatorUse::kReadWrite, OperandType::kFlag8 | |
ToName, AccumulatorUse::kRead, OperandType::kRegOut | |
ToNumber, AccumulatorUse::kReadWrite, OperandType::kIdx | |
ToNumeric, AccumulatorUse::kReadWrite, OperandType::kIdx | |
ToObject, AccumulatorUse::kRead, OperandType::kRegOut | |
CreateRegExpLiteral, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8 | |
CreateArrayLiteral, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8 | |
CreateEmptyArrayLiteral, AccumulatorUse::kWrite, OperandType::kIdx | |
CreateObjectLiteral, AccumulatorUse::kNone, OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8, OperandType::kRegOut | |
CreateEmptyObjectLiteral, AccumulatorUse::kWrite | |
GetTemplateObject, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx | |
CreateClosure, AccumulatorUse::kWrite, OperandType::kIdx, OperandType::kIdx, OperandType::kFlag8 | |
CreateBlockContext, AccumulatorUse::kReadWrite, OperandType::kIdx | |
CreateCatchContext, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx, OperandType::kIdx | |
CreateFunctionContext, AccumulatorUse::kWrite, OperandType::kUImm | |
CreateEvalContext, AccumulatorUse::kWrite, OperandType::kUImm | |
CreateWithContext, AccumulatorUse::kReadWrite, OperandType::kReg, OperandType::kIdx | |
CreateMappedArguments, AccumulatorUse::kWrite | |
CreateUnmappedArguments, AccumulatorUse::kWrite | |
CreateRestParameter, AccumulatorUse::kWrite | |
JumpLoop, AccumulatorUse::kNone, OperandType::kUImm, OperandType::kImm | |
Jump, AccumulatorUse::kNone, OperandType::kUImm | |
JumpConstant, AccumulatorUse::kNone, OperandType::kIdx | |
JumpIfNullConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfNotNullConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfUndefinedConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfNotUndefinedConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfTrueConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfFalseConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfJSReceiverConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfToBooleanTrueConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfToBooleanFalseConstant, AccumulatorUse::kRead, OperandType::kIdx | |
JumpIfToBooleanTrue, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfToBooleanFalse, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfTrue, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfFalse, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfNull, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfNotNull, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfUndefined, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfNotUndefined, AccumulatorUse::kRead, OperandType::kUImm | |
JumpIfJSReceiver, AccumulatorUse::kRead, OperandType::kUImm | |
SwitchOnSmiNoFeedback, AccumulatorUse::kRead, OperandType::kIdx, OperandType::kUImm, OperandType::kImm | |
ForInEnumerate, AccumulatorUse::kWrite, OperandType::kReg | |
ForInPrepare, AccumulatorUse::kRead, OperandType::kRegOutTriple, OperandType::kIdx | |
ForInContinue, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg | |
ForInNext, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kReg, OperandType::kRegPair, OperandType::kIdx | |
ForInStep, AccumulatorUse::kWrite, OperandType::kReg | |
StackCheck, AccumulatorUse::kNone | |
SetPendingMessage, AccumulatorUse::kReadWrite | |
Throw, AccumulatorUse::kRead | |
ReThrow, AccumulatorUse::kRead | |
Return, AccumulatorUse::kRead | |
ThrowReferenceErrorIfHole, AccumulatorUse::kRead, OperandType::kIdx | |
ThrowSuperNotCalledIfHole, AccumulatorUse::kRead | |
ThrowSuperAlreadyCalledIfNotHole, AccumulatorUse::kRead | |
SwitchOnGeneratorState, AccumulatorUse::kNone, OperandType::kReg, OperandType::kIdx, OperandType::kUImm | |
SuspendGenerator, AccumulatorUse::kRead, OperandType::kReg, OperandType::kRegList, OperandType::kRegCount, OperandType::kUImm | |
ResumeGenerator, AccumulatorUse::kWrite, OperandType::kReg, OperandType::kRegOutList, OperandType::kRegCount | |
Debugger, AccumulatorUse::kNone | |
IncBlockCounter, AccumulatorUse::kNone, OperandType::kIdx | |
Abort, AccumulatorUse::kNone, OperandType::kIdx | |
Illegal, AccumulatorUse::kNone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2006-2008 the V8 project authors. All rights reserved. | |
// Copyright 2013-2017 Intel Corp. Author: Roger Wang <[email protected]> | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
#if defined(__clang__) | |
#pragma clang diagnostic ignored "-Wundefined-inline" | |
#endif | |
#include <errno.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include "src/v8.h" | |
#include "include/libplatform/libplatform.h" | |
#include "src/assembler.h" | |
#include "src/base/platform/platform.h" | |
#include "src/compiler.h" | |
#include "src/factory.h" | |
#include "src/isolate-inl.h" | |
#include "src/flags.h" | |
#include "src/snapshot/natives.h" | |
#include "src/snapshot/code-serializer.h" | |
#include "src/snapshot/partial-serializer.h" | |
#include "src/snapshot/startup-serializer.h" | |
#include "src/parsing/preparse-data.h" | |
using namespace v8; | |
namespace { | |
} //namespace | |
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |
public: | |
virtual void* Allocate(size_t length) { | |
void* data = AllocateUninitialized(length); | |
return data == NULL ? data : memset(data, 0, length); | |
} | |
virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | |
virtual void Free(void* data, size_t) { free(data); } | |
}; | |
class SnapshotWriter { | |
public: | |
explicit SnapshotWriter(const char* snapshot_file) | |
: fp_(GetFileDescriptorOrDie(snapshot_file)) | |
{} | |
~SnapshotWriter() { | |
fclose(fp_); | |
} | |
void WriteSnapshot(void* buffer, int length) const { | |
size_t written = fwrite(buffer, 1, length, fp_); | |
if (written != static_cast<size_t>(length)) { | |
i::PrintF("Writing snapshot file failed.. Aborting.\n"); | |
exit(1); | |
} | |
} | |
private: | |
FILE* GetFileDescriptorOrDie(const char* filename) { | |
FILE* fp = base::OS::FOpen(filename, "wb"); | |
if (fp == NULL) { | |
i::PrintF("Unable to open file \"%s\" for writing.\n", filename); | |
exit(1); | |
} | |
return fp; | |
} | |
FILE* fp_; | |
}; | |
int main(int argc, char** argv) { | |
// By default, log code create information in the snapshot. | |
i::FLAG_log_code = true; | |
// Omit from the snapshot natives for features that can be turned off | |
// at runtime. | |
i::FLAG_harmony_shipping = false; | |
i::FLAG_logfile_per_isolate = false; | |
//i::FLAG_serialize_toplevel = true; | |
i::FLAG_lazy = false; | |
// Print the usage if an error occurs when parsing the command line | |
// flags or if the help flag is set. | |
int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | |
if (result > 0 || argc != 2 || i::FLAG_help) { | |
::printf("Usage: %s [flag] ... jsfile outfile\n", argv[0]); | |
i::FlagList::PrintHelp(); | |
return !i::FLAG_help; | |
} | |
i::CpuFeatures::Probe(true); | |
V8::InitializeICUDefaultLocation(argv[0]); | |
v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | |
v8::V8::InitializePlatform(platform); | |
v8::V8::Initialize(); | |
v8::Isolate::CreateParams create_params; | |
ArrayBufferAllocator array_buffer_allocator; | |
create_params.array_buffer_allocator = &array_buffer_allocator; | |
v8::Isolate* isolate = v8::Isolate::New(create_params); | |
{ | |
v8::Isolate::Scope isolate_scope(isolate); | |
v8::HandleScope handle_scope(isolate); | |
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | |
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | |
v8::Context::Scope scope(context); | |
FILE* file = v8::base::OS::FOpen(argv[1], "rb"); | |
if (file == NULL) { | |
fprintf(stderr, "Failed to open '%s': errno %d\n", argv[1], errno); | |
exit(1); | |
} | |
fseek(file, 0, SEEK_END); | |
long size = ftell(file); | |
rewind(file); | |
char* chars = new char[size + 1]; | |
chars[size] = '\0'; | |
for (long i = 0; i < size;) { | |
int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | |
if (read < 0) { | |
fprintf(stderr, "Failed to read '%s': errno %d\n", argv[1], errno); | |
exit(1); | |
} | |
i += read; | |
} | |
fclose(file); | |
//Local<String> source_str = String::NewFromUtf8(isolate, chars); | |
//Local<String> filename = String::NewFromUtf8(isolate, argv[1]); | |
TryCatch try_catch(isolate); | |
//i::Isolate* iso = reinterpret_cast<i::Isolate*>(isolate); | |
uint8_t *data = reinterpret_cast<uint8_t*>(chars); | |
v8::ScriptCompiler::CachedData* cache; | |
cache = new v8::ScriptCompiler::CachedData(data, (int)size, v8::ScriptCompiler::CachedData::BufferNotOwned); | |
v8::Handle<v8::String> source_string = v8::String::NewFromUtf8(isolate, ""); | |
v8::Local<v8::UnboundScript> script; | |
v8::ScriptCompiler::Source source(source_string, cache); | |
script = v8::ScriptCompiler::CompileUnboundScript( | |
isolate, &source, v8::ScriptCompiler::kConsumeCodeCache).ToLocalChecked(); | |
CHECK(!cache->rejected); | |
} | |
V8::Dispose(); | |
V8::ShutdownPlatform(); | |
delete platform; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment