Status: New
Owner: ----
New issue 3647 by [email protected]:
PersistentBase<v8::Value>::SetWeak does not work with v8::Number when the
value is zero
https://code.google.com/p/v8/issues/detail?id=3647
sscce:
#include <v8.h>
#include <memory>
namespace {
typedef v8::CopyablePersistentTraits<v8::Value>::CopyablePersistent
MyPersistent;
typedef v8::WeakCallbackData<v8::Value, MyPersistent> MyWeakCallbackData;;
void MyDisposeCallback(const MyWeakCallbackData& callbackData) {
// it's never called
std::unique_ptr<MyPersistent> objectPointer{
callbackData.GetParameter() };
objectPointer->Reset();
}
}
int main() {
v8::V8::Initialize();
v8::Isolate* isolate = v8::Isolate::New();
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
{
int crash_value = 0; // 0 - crash, 1 - works fine
auto localZeroNumber = v8::Number::New(isolate, crash_value);
auto persistentZeroValue = new MyPersistent(isolate, localZeroNumber);
if (!persistentZeroValue->IsWeak()) {
// Crash in SetWeak
persistentZeroValue->SetWeak(persistentZeroValue,
static_cast<MyWeakCallbackData::Callback>(&MyDisposeCallback));
}
}
}
// it also crashes here
//isolate->IdleNotification(1000);
v8::V8::Dispose();
return 0;
}
The callstack
my-v8.exe!v8::internal::GlobalHandles::Node::MakeWeak(void * parameter,
void (const v8::WeakCallbackData<v8::Value,void> &) * weak_callback) Line
210 C++
my-v8.exe!v8::internal::GlobalHandles::MakeWeak(v8::internal::Object * *
location, void * parameter, void (const
v8::WeakCallbackData<v8::Value,void> &) * weak_callback) Line 482 C++
my-v8.exe!v8::V8::MakeWeak(v8::internal::Object * * object, void *
parameters, void (const v8::WeakCallbackData<v8::Value,void> &) *
weak_callback) Line 515 C++
my-v8.exe!v8::PersistentBase<v8::Value>::SetWeak<v8::Value,v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value>
>(v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value> > *
parameter, void (const
v8::WeakCallbackData<v8::Value,v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value>
> &) * callback) Line 6211 C++
my-v8.exe!v8::PersistentBase<v8::Value>::SetWeak<v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value>
>(v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value> > *
parameter, void (const
v8::WeakCallbackData<v8::Value,v8::Persistent<v8::Value,v8::CopyablePersistentTraits<v8::Value>
> &) * callback) Line 6221 C++
my-v8.exe!main() Line 66 C++
my-v8.exe!__tmainCRTStartup() Line 255 C
my-v8.exe!mainCRTStartup() Line 165 C
kernel32.dll!@BaseThreadInitThunk@12 () Unknown
ntdll.dll!__RtlUserThreadStart() Unknown
ntdll.dll!__RtlUserThreadStart@8 () Unknown
Crashes on the line
CHECK(object_ != NULL);
`v8::Number::New(isolate, 0)` sets internal object to null, while
`v8::Number::New(isolate, 1)` sets it to 2 and it works.
JIC, Having read
https://groups.google.com/forum/#!topic/v8-users/6kSAbnUb-rQ and
https://groups.google.com/d/topic/v8-users/ta9wkdEY08o/discussion and I
don't expect the correct behaviour, but I am confident that it should not
crash at least.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.