OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef V0CustomElementBinding_h | 31 #ifndef V8ObjectConstructor_h |
32 #define V0CustomElementBinding_h | 32 #define V8ObjectConstructor_h |
33 | 33 |
34 #include <memory> | 34 #include "platform/PlatformExport.h" |
35 | 35 #include "platform/bindings/V8PerIsolateData.h" |
36 #include "bindings/core/v8/ScopedPersistent.h" | |
37 #include "platform/wtf/Allocator.h" | 36 #include "platform/wtf/Allocator.h" |
38 #include "v8/include/v8.h" | 37 #include "v8/include/v8.h" |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 class V0CustomElementBinding { | 41 class ConstructorMode { |
43 USING_FAST_MALLOC(V0CustomElementBinding); | 42 STACK_ALLOCATED(); |
44 | 43 |
45 public: | 44 public: |
46 static std::unique_ptr<V0CustomElementBinding> Create( | 45 enum Mode { kWrapExistingObject, kCreateNewObject }; |
47 v8::Isolate*, | 46 |
48 v8::Local<v8::Object> prototype); | 47 ConstructorMode(v8::Isolate* isolate) : isolate_(isolate) { |
49 ~V0CustomElementBinding(); | 48 V8PerIsolateData* data = V8PerIsolateData::From(isolate_); |
| 49 previous_ = data->constructor_mode_; |
| 50 data->constructor_mode_ = kWrapExistingObject; |
| 51 } |
| 52 |
| 53 ~ConstructorMode() { |
| 54 V8PerIsolateData* data = V8PerIsolateData::From(isolate_); |
| 55 data->constructor_mode_ = previous_; |
| 56 } |
| 57 |
| 58 static bool Current(v8::Isolate* isolate) { |
| 59 return V8PerIsolateData::From(isolate)->constructor_mode_; |
| 60 } |
50 | 61 |
51 private: | 62 private: |
52 V0CustomElementBinding(v8::Isolate*, v8::Local<v8::Object> prototype); | 63 v8::Isolate* isolate_; |
53 ScopedPersistent<v8::Object> prototype_; | 64 bool previous_; |
| 65 }; |
| 66 |
| 67 class PLATFORM_EXPORT V8ObjectConstructor { |
| 68 STATIC_ONLY(V8ObjectConstructor); |
| 69 |
| 70 public: |
| 71 static v8::MaybeLocal<v8::Object> NewInstance( |
| 72 v8::Isolate*, |
| 73 v8::Local<v8::Function>, |
| 74 int argc = 0, |
| 75 v8::Local<v8::Value> argv[] = nullptr); |
| 76 |
| 77 static void IsValidConstructorMode( |
| 78 const v8::FunctionCallbackInfo<v8::Value>&); |
54 }; | 79 }; |
55 | 80 |
56 } // namespace blink | 81 } // namespace blink |
57 | 82 |
58 #endif // V0CustomElementBinding_h | 83 #endif // V8ObjectConstructor_h |
OLD | NEW |