[Webkit-unassigned] [Bug 70015] Constructor should not be called if the object is being constructed inside WebCore

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Oct 14 05:14:03 PDT 2011


https://bugs.webkit.org/show_bug.cgi?id=70015





--- Comment #9 from Dominic Cooney <dominicc at chromium.org>  2011-10-14 05:14:02 PST ---
(in reply to comment #5):

> Adam: AllowAllocation::current() just calls Isolate::GetCurrent(), and Isolate::GetCurrent() returns the
> entered isolate for the current thread or NULL in case there is no current isolate (See the comment of
> Isolate::GetCurrent(): http://codesearch.google.com/codesearch#OAMlx_jo-
> ck/src/v8/include/v8.h&type=cs&l=2727). In my understanding, this means that
> AllowAllocation::current() returns true if it is called inside toV8() which is invoked from the WebCore
> context, which is the case where constructorCallback() should not be executed.

This is not quite right. One thing that makes this confusing is that the name ”AllowAllocation” is not a good name any more. Let me try to explain:

As described in the description, V8 calls C++ constructor callbacks in two situations:

1. The author allocates an instance via "new X"; X is a function with a C++ construct callback.

2. C++ allocates an instance via the function template.

Typical DOM constructor functions disallow the first way—they throw.

AllowAllocation is an RAII guard. When the bindings are doing number two (ugh… that sounds bad…) it puts an AllowAllocation on the stack, the callback runs and checks the guard (this is _all_ the typical DOM constructor callback does—it is V8Proxy::checkNewLegal.)

The guard is not just "is an isolate/V8 context present." It is, _are "allocations allowed"_ in the current isolate. A boolean that is set and restored by RAII ctor and dtor.

So you can see why AllowAllocations is no longer an appropriate name. Because method 1—the author allocates via "new X"—works, the allocation should be "allowed." But the C++ callback needs to discern when it is invoked by the author, and should allocate the C++ object to wrap, or when it is invoked by the wrapper table which will hand it a pointer to wrap.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list