Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: Source/bindings/v8/V8AdaptorFunction.h

Issue 16708002: Simplify Custom Element constructors to be functions, not wrappers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/CustomElementHelpers.cpp ('k') | Source/bindings/v8/V8AdaptorFunction.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef V8AdaptorFunction_h
32 #define V8AdaptorFunction_h
33
34 #include "bindings/v8/V8Binding.h"
35 #include "bindings/v8/V8HiddenPropertyName.h"
36 #include "bindings/v8/WrapperTypeInfo.h"
37 #include "wtf/PassRefPtr.h"
38
39 namespace WebCore {
40
41 //
42 // FIXME(https://bugs.webkit.org/show_bug.cgi?id=108138):
43 // V8AdaptorFunction class and V8WrapAsFunction IDL attribute are needed for two reasons:
44 // - 1) V8 doesn't allow expanding the internal field of function objects. https ://code.google.com/p/v8/issues/detail?id=837
45 // WebKit need it to associate each wrapper to its backing C++ object. We s tore it in a hidden property of the wrapped object.
46 // - 2) Binding codebase assumes every wrapper object is created through ObjectT emplate::NewInstance(), not FunctionTemplate::GetFunction().
47 // Once 1) is addresssed, we could attack 2) with it.
48 //
49 class V8AdaptorFunction {
50 public:
51 static WrapperTypeInfo info;
52 static v8::Handle<v8::Object> unwrap(v8::Handle<v8::Function>);
53 static v8::Handle<v8::Function> wrap(v8::Handle<v8::Object>, const AtomicStr ing& name, v8::Isolate*);
54 static v8::Handle<v8::Function> get(v8::Handle<v8::Object>);
55
56 static v8::Handle<v8::FunctionTemplate> getTemplate(v8::Isolate*, WrapperWor ldType);
57 static v8::Handle<v8::FunctionTemplate> configureTemplate(v8::Handle<v8::Fun ctionTemplate>);
58 static void invocationCallback(const v8::FunctionCallbackInfo<v8::Value>&);
59 };
60
61 inline v8::Handle<v8::Object> V8AdaptorFunction::unwrap(v8::Handle<v8::Function> function)
62 {
63 v8::Handle<v8::Value> wrapped = function->GetHiddenValue(V8HiddenPropertyNam e::adaptorFunctionPeer());
64 ASSERT(!wrapped.IsEmpty());
65 ASSERT(wrapped->IsObject());
66 return v8::Handle<v8::Object>::Cast(wrapped);
67 }
68
69 inline v8::Handle<v8::Function> V8AdaptorFunction::get(v8::Handle<v8::Object> ob ject)
70 {
71 v8::Handle<v8::Value> adaptorFunction = object->GetHiddenValue(V8HiddenPrope rtyName::adaptorFunctionPeer());
72 ASSERT(!adaptorFunction.IsEmpty());
73 ASSERT(adaptorFunction->IsFunction());
74 return v8::Handle<v8::Function>::Cast(adaptorFunction);
75 }
76
77 } // namespace WebCore
78
79 #endif // V8AdaptorFunction_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/CustomElementHelpers.cpp ('k') | Source/bindings/v8/V8AdaptorFunction.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698