Here is a program that demonstrates this issue: (removing line #28 eliminates the problem)
1 #include <iostream>
2 #include <string.h>
3 #include "v8/libplatform/libplatform.h"
4 #include "v8/v8.h"
5
6 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
7 public:
8 virtual void* Allocate(size_t length) {
9 void* data = AllocateUninitialized(length);
10 return data == NULL ? data : memset(data, 0, length);
11 }
12 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
13 virtual void Free(void* data, size_t) { free(data); }
14 };
15
16 void GetProperty(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info)
17 {
18 v8::String::Utf8Value asciiprop(property);
19 std::cout << "GETTER: property=" << *asciiprop << std::endl;
20 }
21
22 void SetProperty(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
23 {
24 v8::Isolate *isolate = info.GetIsolate();
25 v8::String::Utf8Value asciiproperty(property);
26 v8::String::Utf8Value asciivalue(value);
27 std::cout << "SETTER: property=" << *asciiproperty << ", value=" << *asciivalue << std::endl;
28 std::cout << "SETTER: hash=" << info.This()->GetIdentityHash() << std::endl;
29 }
30
31 int main(int argc, char* argv[])
32 {
33 // Initialize V8.
34 v8::V8::InitializeICU();
35 v8::V8::InitializeExternalStartupData(argv[0]);
36 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
37 v8::V8::InitializePlatform(platform);
38 v8::V8::Initialize();
39
40 // Create a new Isolate and make it the current one.
41 ArrayBufferAllocator allocator;
42 v8::Isolate::CreateParams create_params;
43 create_params.array_buffer_allocator = &allocator;
44 v8::Isolate* isolate = v8::Isolate::New(create_params);
45 {
46 v8::Isolate::Scope isolate_scope(isolate);
47 v8::HandleScope handle_scope(isolate);
48 v8::Local<v8::ObjectTemplate> objectTemplate = v8::ObjectTemplate::New();
49 objectTemplate->SetNamedPropertyHandler(GetProperty,SetProperty);
50 v8::Local<v8::Context> ctx = v8::Context::New(isolate);
51 v8::Context::Scope context_scope(ctx);
52
53 // run tests
54 v8::Local<v8::String> fooStr = v8::String::NewFromUtf8(isolate, "foo");
55 v8::Local<v8::String> barStr = v8::String::NewFromUtf8(isolate, "bar");
56 v8::Local<v8::Object> obj = objectTemplate->NewInstance();
57 obj->Set(fooStr, barStr);
58 }
59
60 // Dispose the isolate and tear down V8.
61 isolate->Dispose();
62 v8::V8::Dispose();
63 v8::V8::ShutdownPlatform();
64 delete platform;
65 return 0;
66 }