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

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: . Created 4 years, 11 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 "bindings/modules/v8/V8BindingForModules.h" 26 #include "bindings/modules/v8/V8BindingForModules.h"
27 27
28 #include "bindings/core/v8/IsolatedScriptController.h"
28 #include "bindings/core/v8/SerializedScriptValue.h" 29 #include "bindings/core/v8/SerializedScriptValue.h"
29 #include "bindings/core/v8/SerializedScriptValueFactory.h" 30 #include "bindings/core/v8/SerializedScriptValueFactory.h"
30 #include "bindings/core/v8/V8ArrayBuffer.h" 31 #include "bindings/core/v8/V8ArrayBuffer.h"
31 #include "bindings/core/v8/V8ArrayBufferView.h" 32 #include "bindings/core/v8/V8ArrayBufferView.h"
32 #include "bindings/core/v8/V8Binding.h" 33 #include "bindings/core/v8/V8Binding.h"
33 #include "bindings/core/v8/V8Blob.h" 34 #include "bindings/core/v8/V8Blob.h"
34 #include "bindings/core/v8/V8DOMStringList.h" 35 #include "bindings/core/v8/V8DOMStringList.h"
35 #include "bindings/core/v8/V8File.h" 36 #include "bindings/core/v8/V8File.h"
36 #include "bindings/core/v8/V8Uint8Array.h" 37 #include "bindings/core/v8/V8Uint8Array.h"
37 #include "bindings/modules/v8/ToV8ForModules.h" 38 #include "bindings/modules/v8/ToV8ForModules.h"
38 #include "bindings/modules/v8/V8IDBCursor.h" 39 #include "bindings/modules/v8/V8IDBCursor.h"
39 #include "bindings/modules/v8/V8IDBCursorWithValue.h" 40 #include "bindings/modules/v8/V8IDBCursorWithValue.h"
40 #include "bindings/modules/v8/V8IDBDatabase.h" 41 #include "bindings/modules/v8/V8IDBDatabase.h"
41 #include "bindings/modules/v8/V8IDBIndex.h" 42 #include "bindings/modules/v8/V8IDBIndex.h"
42 #include "bindings/modules/v8/V8IDBKeyRange.h" 43 #include "bindings/modules/v8/V8IDBKeyRange.h"
43 #include "bindings/modules/v8/V8IDBObjectStore.h" 44 #include "bindings/modules/v8/V8IDBObjectStore.h"
45 #include "bindings/modules/v8/V8WorkletGlobalScope.h"
44 #include "core/dom/DOMArrayBuffer.h" 46 #include "core/dom/DOMArrayBuffer.h"
45 #include "core/dom/DOMArrayBufferView.h" 47 #include "core/dom/DOMArrayBufferView.h"
48 #include "core/dom/ExecutionContext.h"
46 #include "modules/indexeddb/IDBKey.h" 49 #include "modules/indexeddb/IDBKey.h"
47 #include "modules/indexeddb/IDBKeyPath.h" 50 #include "modules/indexeddb/IDBKeyPath.h"
48 #include "modules/indexeddb/IDBKeyRange.h" 51 #include "modules/indexeddb/IDBKeyRange.h"
49 #include "modules/indexeddb/IDBTracing.h" 52 #include "modules/indexeddb/IDBTracing.h"
50 #include "modules/indexeddb/IDBValue.h" 53 #include "modules/indexeddb/IDBValue.h"
54 #include "modules/worklet/WorkletGlobalScope.h"
51 #include "platform/RuntimeEnabledFeatures.h" 55 #include "platform/RuntimeEnabledFeatures.h"
52 #include "platform/SharedBuffer.h" 56 #include "platform/SharedBuffer.h"
53 #include "wtf/MathExtras.h" 57 #include "wtf/MathExtras.h"
54 #include "wtf/Vector.h" 58 #include "wtf/Vector.h"
55 59
56 namespace blink { 60 namespace blink {
57 61
58 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, const IDBValue *); 62 static v8::Local<v8::Value> deserializeIDBValueData(v8::Isolate*, const IDBValue *);
59 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*);
60 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
152 case IDBAny::IntegerType: 156 case IDBAny::IntegerType:
153 return v8::Number::New(isolate, impl->integer()); 157 return v8::Number::New(isolate, impl->integer());
154 case IDBAny::KeyType: 158 case IDBAny::KeyType:
155 return toV8(impl->key(), creationContext, isolate); 159 return toV8(impl->key(), creationContext, isolate);
156 } 160 }
157 161
158 ASSERT_NOT_REACHED(); 162 ASSERT_NOT_REACHED();
159 return v8::Undefined(isolate); 163 return v8::Undefined(isolate);
160 } 164 }
161 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 IsolatedScriptController* 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
162 static const size_t maximumDepth = 2000; 183 static const size_t maximumDepth = 2000;
163 184
164 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)
165 { 186 {
166 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value())) 187 if (value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value()))
167 return IDBKey::createNumber(value.As<v8::Number>()->Value()); 188 return IDBKey::createNumber(value.As<v8::Number>()->Value());
168 if (value->IsString()) 189 if (value->IsString())
169 return IDBKey::createString(toCoreString(value.As<v8::String>())); 190 return IDBKey::createString(toCoreString(value.As<v8::String>()));
170 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf())) 191 if (value->IsDate() && !std::isnan(value.As<v8::Date>()->ValueOf()))
171 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
509 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), exceptionState, allowExperimentalTypes); 530 IDBKey* expectedKey = createIDBKeyFromValueAndKeyPath(isolate, scriptValue.v 8Value(), value->keyPath(), exceptionState, allowExperimentalTypes);
510 ASSERT(!exceptionState.hadException()); 531 ASSERT(!exceptionState.hadException());
511 if (expectedKey && expectedKey->isEqual(value->primaryKey())) 532 if (expectedKey && expectedKey->isEqual(value->primaryKey()))
512 return; 533 return;
513 534
514 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath()); 535 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), value->keyPath());
515 ASSERT_UNUSED(injected, injected); 536 ASSERT_UNUSED(injected, injected);
516 } 537 }
517 #endif 538 #endif
518 539
540 ExecutionContext* toExecutionContextForModules(v8::Local<v8::Context> context)
541 {
542 if (context.IsEmpty())
543 return 0;
haraken 2016/01/05 06:08:06 nullptr
ikilpatrick 2016/01/07 22:47:35 Done.
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);
548 // FIXME: Is this line of code reachable?
549 return 0;
haraken 2016/01/05 06:08:06 nullptr
ikilpatrick 2016/01/07 22:47:35 Done.
550 }
551
552 v8::Local<v8::Context> toV8ContextForModules(ExecutionContext* context)
553 {
554 if (context->isWorkletGlobalScope()) {
555 if (IsolatedScriptController* script = toWorkletGlobalScope(context)->sc ript()) {
556 if (script->scriptState()->contextIsValid())
557 return script->scriptState()->context();
558 }
559 }
560 return v8::Local<v8::Context>();
561 }
562
519 } // namespace blink 563 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698