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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp

Issue 1535943005: Initial implementation of bindings and basic classes for worklets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix memory leak. Created 4 years, 12 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "bindings/modules/v8/V8BindingForModules.h" 27 #include "bindings/modules/v8/V8BindingForModules.h"
28 28
29 #include "bindings/core/v8/GlobalScopeScriptController.h"
29 #include "bindings/core/v8/SerializedScriptValue.h" 30 #include "bindings/core/v8/SerializedScriptValue.h"
30 #include "bindings/core/v8/SerializedScriptValueFactory.h" 31 #include "bindings/core/v8/SerializedScriptValueFactory.h"
31 #include "bindings/core/v8/V8ArrayBuffer.h" 32 #include "bindings/core/v8/V8ArrayBuffer.h"
32 #include "bindings/core/v8/V8ArrayBufferView.h" 33 #include "bindings/core/v8/V8ArrayBufferView.h"
33 #include "bindings/core/v8/V8Binding.h" 34 #include "bindings/core/v8/V8Binding.h"
34 #include "bindings/core/v8/V8Blob.h" 35 #include "bindings/core/v8/V8Blob.h"
35 #include "bindings/core/v8/V8DOMStringList.h" 36 #include "bindings/core/v8/V8DOMStringList.h"
36 #include "bindings/core/v8/V8File.h" 37 #include "bindings/core/v8/V8File.h"
37 #include "bindings/core/v8/V8Uint8Array.h" 38 #include "bindings/core/v8/V8Uint8Array.h"
38 #include "bindings/modules/v8/ToV8ForModules.h" 39 #include "bindings/modules/v8/ToV8ForModules.h"
39 #include "bindings/modules/v8/V8IDBCursor.h" 40 #include "bindings/modules/v8/V8IDBCursor.h"
40 #include "bindings/modules/v8/V8IDBCursorWithValue.h" 41 #include "bindings/modules/v8/V8IDBCursorWithValue.h"
41 #include "bindings/modules/v8/V8IDBDatabase.h" 42 #include "bindings/modules/v8/V8IDBDatabase.h"
42 #include "bindings/modules/v8/V8IDBIndex.h" 43 #include "bindings/modules/v8/V8IDBIndex.h"
43 #include "bindings/modules/v8/V8IDBKeyRange.h" 44 #include "bindings/modules/v8/V8IDBKeyRange.h"
44 #include "bindings/modules/v8/V8IDBObjectStore.h" 45 #include "bindings/modules/v8/V8IDBObjectStore.h"
46 #include "bindings/modules/v8/V8WorkletGlobalScope.h"
45 #include "core/dom/DOMArrayBuffer.h" 47 #include "core/dom/DOMArrayBuffer.h"
46 #include "core/dom/DOMArrayBufferView.h" 48 #include "core/dom/DOMArrayBufferView.h"
47 #include "modules/indexeddb/IDBKey.h" 49 #include "modules/indexeddb/IDBKey.h"
48 #include "modules/indexeddb/IDBKeyPath.h" 50 #include "modules/indexeddb/IDBKeyPath.h"
49 #include "modules/indexeddb/IDBKeyRange.h" 51 #include "modules/indexeddb/IDBKeyRange.h"
50 #include "modules/indexeddb/IDBTracing.h" 52 #include "modules/indexeddb/IDBTracing.h"
51 #include "modules/indexeddb/IDBValue.h" 53 #include "modules/indexeddb/IDBValue.h"
54 #include "modules/worklet/WorkletGlobalScope.h"
52 #include "platform/RuntimeEnabledFeatures.h" 55 #include "platform/RuntimeEnabledFeatures.h"
53 #include "platform/SharedBuffer.h" 56 #include "platform/SharedBuffer.h"
54 #include "wtf/MathExtras.h" 57 #include "wtf/MathExtras.h"
55 #include "wtf/Vector.h" 58 #include "wtf/Vector.h"
56 59
57 namespace blink { 60 namespace blink {
58 61
59 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, const IDBValue *); 62 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, const IDBValue *);
60 static v8::Local<v8::Value> deserializeIDBValue(v8::Isolate*, v8::Local<v8::Obje ct> creationContext, const IDBValue*); 63 static v8::Local<v8::Value> deserializeIDBValue(v8::Isolate*, v8::Local<v8::Obje ct> creationContext, const IDBValue*);
61 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate*, v8::Local<v8: :Object> creationContext, const Vector<RefPtr<IDBValue>>*); 64 static v8::Local<v8::Value> deserializeIDBValueArray(v8::Isolate*, v8::Local<v8: :Object> creationContext, const Vector<RefPtr<IDBValue>>*);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 case IDBAny::IntegerType: 156 case IDBAny::IntegerType:
154 return v8::Number::New(isolate, impl->integer()); 157 return v8::Number::New(isolate, impl->integer());
155 case IDBAny::KeyType: 158 case IDBAny::KeyType:
156 return toV8(impl->key(), creationContext, isolate); 159 return toV8(impl->key(), creationContext, isolate);
157 } 160 }
158 161
159 ASSERT_NOT_REACHED(); 162 ASSERT_NOT_REACHED();
160 return v8::Undefined(isolate); 163 return v8::Undefined(isolate);
161 } 164 }
162 165
166 v8::Local<v8::Value> toV8(WorkletGlobalScope* impl, v8::Local<v8::Object> creati onContext, v8::Isolate* isolate)
167 {
168 // Notice that we explicitly ignore creationContext because the
169 // WorkletGlobalScope has its own creationContext.
170
171 if (UNLIKELY(!impl))
172 return v8::Null(isolate);
173
174 GlobalScopeScriptController* script = impl->script();
175 if (!script)
176 return v8::Null(isolate);
177
178 v8::Local<v8::Object> global = script->context()->Global();
179 ASSERT(!global.IsEmpty());
180 return global;
181 }
182
163 static const size_t maximumDepth = 2000; 183 static const size_t maximumDepth = 2000;
164 184
165 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Vector<v8::Local<v8::Array>>& stack, ExceptionState& exceptionState, bool allowExperimentalTypes = false) 185 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Vector<v8::Local<v8::Array>>& stack, ExceptionState& exceptionState, bool allowExperimentalTypes = false)
166 { 186 {
167 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) 187 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value()))
168 return IDBKey::createNumber(value.As<v8::Number>()->Value()); 188 return IDBKey::createNumber(value.As<v8::Number>()->Value());
169 if (value->IsString()) 189 if (value->IsString())
170 return IDBKey::createString(toCoreString(value.As<v8::String>())); 190 return IDBKey::createString(toCoreString(value.As<v8::String>()));
171 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) 191 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf()))
172 return IDBKey::createDate(value.As<v8::Date>()->ValueOf()); 192 return IDBKey::createDate(value.As<v8::Date>()->ValueOf());
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), exceptionState, allowExperimentalTypes); 530 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), exceptionState, allowExperimentalTypes);
511 ASSERT(!exceptionState.hadException()); 531 ASSERT(!exceptionState.hadException());
512 if (expectedKey && expectedKey->isEqual(value->primaryKey())) 532 if (expectedKey && expectedKey->isEqual(value->primaryKey()))
513 return; 533 return;
514 534
515 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); 535 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath());
516 ASSERT_UNUSED(injected, injected); 536 ASSERT_UNUSED(injected, injected);
517 } 537 }
518 #endif 538 #endif
519 539
540 ExecutionContext* toExecutionContextForModules(v8::Local<v8::Context> context)
541 {
542 if (context.IsEmpty())
543 return 0;
544 v8::Local<v8::Object> global = context->Global();
545 v8::Local<v8::Object> workletWrapper = V8WorkletGlobalScope::findInstanceInP rototypeChain(global, context->GetIsolate());
546 if (!workletWrapper.IsEmpty())
547 return V8WorkletGlobalScope::toImpl(workletWrapper)->executionContext();
548 // FIXME: Is this line of code reachable?
549 return 0;
550 }
551
520 } // namespace blink 552 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698