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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8Binding.h

Issue 2707243006: [SharedArrayBuffer] Prevent SharedArrayBuffer being used in Web APIs (Closed)
Patch Set: update comment, add TODO Created 3 years, 8 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. 3 * Copyright (C) 2012 Ericsson AB. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 29 matching lines...) Expand all
40 #include "bindings/core/v8/ScriptState.h" 40 #include "bindings/core/v8/ScriptState.h"
41 #include "bindings/core/v8/ScriptValue.h" 41 #include "bindings/core/v8/ScriptValue.h"
42 #include "bindings/core/v8/ScriptWrappable.h" 42 #include "bindings/core/v8/ScriptWrappable.h"
43 #include "bindings/core/v8/V8BindingMacros.h" 43 #include "bindings/core/v8/V8BindingMacros.h"
44 #include "bindings/core/v8/V8PerIsolateData.h" 44 #include "bindings/core/v8/V8PerIsolateData.h"
45 #include "bindings/core/v8/V8ScriptRunner.h" 45 #include "bindings/core/v8/V8ScriptRunner.h"
46 #include "bindings/core/v8/V8StringResource.h" 46 #include "bindings/core/v8/V8StringResource.h"
47 #include "bindings/core/v8/V8ThrowException.h" 47 #include "bindings/core/v8/V8ThrowException.h"
48 #include "bindings/core/v8/V8ValueCache.h" 48 #include "bindings/core/v8/V8ValueCache.h"
49 #include "core/CoreExport.h" 49 #include "core/CoreExport.h"
50 #include "core/dom/NotShared.h"
50 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
51 #include "platform/wtf/text/AtomicString.h" 52 #include "platform/wtf/text/AtomicString.h"
52 #include "platform/wtf/text/StringView.h" 53 #include "platform/wtf/text/StringView.h"
53 #include "v8/include/v8.h" 54 #include "v8/include/v8.h"
54 55
55 namespace blink { 56 namespace blink {
56 57
57 class DOMWindow; 58 class DOMWindow;
58 class EventListener; 59 class EventListener;
59 class EventTarget; 60 class EventTarget;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), 210 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(),
210 callback_info.GetIsolate())); 211 callback_info.GetIsolate()));
211 } 212 }
212 213
213 template <typename CallbackInfo, typename T> 214 template <typename CallbackInfo, typename T>
214 inline void V8SetReturnValue(const CallbackInfo& callback_info, 215 inline void V8SetReturnValue(const CallbackInfo& callback_info,
215 PassRefPtr<T> impl) { 216 PassRefPtr<T> impl) {
216 V8SetReturnValue(callback_info, impl.Get()); 217 V8SetReturnValue(callback_info, impl.Get());
217 } 218 }
218 219
220 template <typename CallbackInfo, typename T>
221 inline void V8SetReturnValue(const CallbackInfo& callbackInfo,
222 NotShared<T> notShared) {
223 V8SetReturnValue(callbackInfo, notShared.View());
224 }
225
219 template <typename CallbackInfo> 226 template <typename CallbackInfo>
220 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, 227 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info,
221 ScriptWrappable* impl) { 228 ScriptWrappable* impl) {
222 ASSERT(DOMWrapperWorld::Current(callback_info.GetIsolate()).IsMainWorld()); 229 ASSERT(DOMWrapperWorld::Current(callback_info.GetIsolate()).IsMainWorld());
223 if (UNLIKELY(!impl)) { 230 if (UNLIKELY(!impl)) {
224 V8SetReturnValueNull(callback_info); 231 V8SetReturnValueNull(callback_info);
225 return; 232 return;
226 } 233 }
227 if (DOMDataStore::SetReturnValueForMainWorld(callback_info.GetReturnValue(), 234 if (DOMDataStore::SetReturnValueForMainWorld(callback_info.GetReturnValue(),
228 impl)) 235 impl))
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 V8SetReturnValueFast(callback_info, impl.Get(), wrappable); 334 V8SetReturnValueFast(callback_info, impl.Get(), wrappable);
328 } 335 }
329 336
330 template <typename CallbackInfo, typename T> 337 template <typename CallbackInfo, typename T>
331 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, 338 inline void V8SetReturnValueFast(const CallbackInfo& callback_info,
332 const v8::Local<T> handle, 339 const v8::Local<T> handle,
333 const ScriptWrappable*) { 340 const ScriptWrappable*) {
334 V8SetReturnValue(callback_info, handle); 341 V8SetReturnValue(callback_info, handle);
335 } 342 }
336 343
344 template <typename CallbackInfo, typename T>
345 inline void V8SetReturnValueFast(const CallbackInfo& callbackInfo,
346 NotShared<T> notShared,
347 const ScriptWrappable* wrappable) {
348 V8SetReturnValueFast(callbackInfo, notShared.View(), wrappable);
349 }
350
337 // Convert v8::String to a WTF::String. If the V8 string is not already 351 // Convert v8::String to a WTF::String. If the V8 string is not already
338 // an external string then it is transformed into an external string at this 352 // an external string then it is transformed into an external string at this
339 // point to avoid repeated conversions. 353 // point to avoid repeated conversions.
340 inline String ToCoreString(v8::Local<v8::String> value) { 354 inline String ToCoreString(v8::Local<v8::String> value) {
341 return V8StringToWebCoreString<String>(value, kExternalize); 355 return V8StringToWebCoreString<String>(value, kExternalize);
342 } 356 }
343 357
344 inline String ToCoreStringWithNullCheck(v8::Local<v8::String> value) { 358 inline String ToCoreStringWithNullCheck(v8::Local<v8::String> value) {
345 if (value.IsEmpty() || value->IsNull()) 359 if (value.IsEmpty() || value->IsNull())
346 return String(); 360 return String();
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1170
1157 // Freeze a V8 object. The type of the first parameter and the return value is 1171 // Freeze a V8 object. The type of the first parameter and the return value is
1158 // intentionally v8::Value so that this function can wrap ToV8(). 1172 // intentionally v8::Value so that this function can wrap ToV8().
1159 // If the argument isn't an object, this will crash. 1173 // If the argument isn't an object, this will crash.
1160 CORE_EXPORT v8::Local<v8::Value> FreezeV8Object(v8::Local<v8::Value>, 1174 CORE_EXPORT v8::Local<v8::Value> FreezeV8Object(v8::Local<v8::Value>,
1161 v8::Isolate*); 1175 v8::Isolate*);
1162 1176
1163 CORE_EXPORT v8::Local<v8::Value> FromJSONString(v8::Isolate*, 1177 CORE_EXPORT v8::Local<v8::Value> FromJSONString(v8::Isolate*,
1164 const String& stringified_json, 1178 const String& stringified_json,
1165 ExceptionState&); 1179 ExceptionState&);
1180
1181 // Ensure that a typed array value is not backed by a SharedArrayBuffer. If it
1182 // is, an exception will be thrown. The return value will use the NotShared
1183 // wrapper type.
1184 template <typename NotSharedType>
1185 NotSharedType ToNotShared(v8::Isolate* isolate,
1186 v8::Local<v8::Value> value,
1187 ExceptionState& exception_state) {
1188 using DOMTypedArray = typename NotSharedType::TypedArrayType;
1189 DOMTypedArray* dom_typed_array =
1190 V8TypeOf<DOMTypedArray>::Type::toImplWithTypeCheck(isolate, value);
1191 if (dom_typed_array && dom_typed_array->IsShared()) {
1192 exception_state.ThrowTypeError(
1193 "The provided ArrayBufferView value must not be shared.");
1194 return NotSharedType();
1195 }
1196 return NotSharedType(dom_typed_array);
1197 }
1198
1166 } // namespace blink 1199 } // namespace blink
1167 1200
1168 #endif // V8Binding_h 1201 #endif // V8Binding_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ToV8.h ('k') | third_party/WebKit/Source/bindings/scripts/v8_attributes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698