javascript - V8: Fatal error: CHECK(V8::ArrayBufferAllocator() != NULL) failed -
i error when try run js code (this + this) v8 (tried master 2 weaks ago, 3.23.17, 3.24.40, 3.25.5; 3.23.0 doesn't work anymore because of api changes):
# # fatal error in ..\..\src\runtime.cc, line 785 # check(v8::arraybufferallocator() != null) failed #
a lot of other js code has worked already, wonder problem is.
it's on win8 x64 build. v8 has been build described in official docs (using gyp + msvc 2012). don't think there problem because worked fine other js code.
i think there might issue v8 itself, not sure...
i asked on mailing-list here.
some c++ code, don't think there problem because worked fine other js code:
#include <string> #include <assert.h> #include <iostream> #include <sstream> #include <iomanip> #include <boost/noncopyable.hpp> #include <v8.h> // create new isolate (completely isolated js vm). struct v8isolate : boost::noncopyable { v8::isolate* isolate; v8isolate() : isolate(v8::isolate::new()) {} ~v8isolate() { isolate->dispose(); } operator v8::isolate*() { return isolate; } v8::isolate* operator->() { return isolate; } }; struct returntype { std::string err; // non-empty if there error returntype(bool success) { assert(success); } returntype(const std::string& _err) : err(_err) { assert(!err.empty()); } returntype(const char* _err) : err(_err) { assert(!err.empty()); } operator bool() const { return err.empty(); } }; #define check_return(cmd) { returntype ret = (cmd); if(!ret) return ret; } using namespace std; using namespace v8; returntype readfile(const std::string& filename, std::string& res) { res = ""; file* f = fopen(filename.c_str(), "r"); if(!f) return "file '" + filename + "' cannot opened"; while(!feof(f) && !ferror(f)) { char buffer[1024 * 8]; size_t s = fread(buffer, 1, sizeof(buffer), f); if(s > 0) res.append(buffer, buffer + s); } auto err = ferror(f); fclose(f); if(err) return "error while reading file '" + filename + "'"; return true; } returntype execjsfile(const std::string& jssourcedir, const std::string& extfilename) { v8::trycatch try_catch; std::string sourcestr; check_return(readfile(jssourcedir + "/" + extfilename, sourcestr)); local<string> origin = string::newfromutf8(isolate::getcurrent(), &extfilename[0], string::knormalstring, (int)extfilename.size()); local<string> source = string::newfromutf8(isolate::getcurrent(), &sourcestr[0], string::knormalstring, (int)sourcestr.size()); local<v8::script> script = script::compile(source, origin); if(script.isempty()) { assert(try_catch.hascaught()); return "js compile failed: " + jsobjtostring(try_catch.exception()); } // run script setup environment local<value> result = script->run(); if(result.isempty()) { assert(try_catch.hascaught()); return "js script execution failed: " + jsreportexceptiontostring(isolate::getcurrent(), &try_catch); } return true; } returntype loadjsgit() { v8isolate isolate; v8::isolate::scope isolatescope(isolate); handlescope handlescope(isolate); handle<context> context = context::new(isolate); context::scope contextscope(context); auto globalobj = context->global(); check_return(execjsfile(".", "global.js")); check_return(execjsfile(".", "jsgit.js")); return true; } int main(int argc, char** argv) { returntype ret = loadjsgit(); if(!ret) cout << "error: " << ret.err << endl; }
you need initialize array buffer allocator.
use malloc, example:
class mallocarraybufferallocator : public v8::arraybuffer::allocator { public: virtual void* allocate(size_t length) { return malloc(length); } virtual void* allocateuninitialized(size_t length) { return malloc(length); } virtual void free(void* data, size_t length) { free(data); } };
initialize:
v8::v8::setarraybufferallocator(new mallocarraybufferallocator);
Comments
Post a Comment