| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 209 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | 210 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), |
| 210 callbackInfo.GetIsolate())); | 211 callbackInfo.GetIsolate())); |
| 211 } | 212 } |
| 212 | 213 |
| 213 template <typename CallbackInfo, typename T> | 214 template <typename CallbackInfo, typename T> |
| 214 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, | 215 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, |
| 215 PassRefPtr<T> impl) { | 216 PassRefPtr<T> impl) { |
| 216 v8SetReturnValue(callbackInfo, impl.get()); | 217 v8SetReturnValue(callbackInfo, 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& callbackInfo, | 227 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, |
| 221 ScriptWrappable* impl) { | 228 ScriptWrappable* impl) { |
| 222 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); | 229 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); |
| 223 if (UNLIKELY(!impl)) { | 230 if (UNLIKELY(!impl)) { |
| 224 v8SetReturnValueNull(callbackInfo); | 231 v8SetReturnValueNull(callbackInfo); |
| 225 return; | 232 return; |
| 226 } | 233 } |
| 227 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(), | 234 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(), |
| 228 impl)) | 235 impl)) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); | 334 v8SetReturnValueFast(callbackInfo, 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& callbackInfo, | 338 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, |
| 332 const v8::Local<T> handle, | 339 const v8::Local<T> handle, |
| 333 const ScriptWrappable*) { | 340 const ScriptWrappable*) { |
| 334 v8SetReturnValue(callbackInfo, handle); | 341 v8SetReturnValue(callbackInfo, 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, Externalize); | 355 return v8StringToWebCoreString<String>(value, Externalize); |
| 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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 | 1166 |
| 1153 // Freeze a V8 object. The type of the first parameter and the return value is | 1167 // Freeze a V8 object. The type of the first parameter and the return value is |
| 1154 // intentionally v8::Value so that this function can wrap ToV8(). | 1168 // intentionally v8::Value so that this function can wrap ToV8(). |
| 1155 // If the argument isn't an object, this will crash. | 1169 // If the argument isn't an object, this will crash. |
| 1156 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, | 1170 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, |
| 1157 v8::Isolate*); | 1171 v8::Isolate*); |
| 1158 | 1172 |
| 1159 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, | 1173 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, |
| 1160 const String& stringifiedJSON, | 1174 const String& stringifiedJSON, |
| 1161 ExceptionState&); | 1175 ExceptionState&); |
| 1176 |
| 1177 // Ensure that a typed array value is not backed by a SharedArrayBuffer. If it |
| 1178 // is, an exception will be thrown. The return value will use the NotShared |
| 1179 // wrapper type. |
| 1180 template <typename NotSharedType> |
| 1181 CORE_EXPORT NotSharedType toNotShared(v8::Isolate* isolate, |
| 1182 v8::Local<v8::Value> value, |
| 1183 ExceptionState& exceptionState) { |
| 1184 using DOMTypedArray = typename NotSharedType::TypedArrayType; |
| 1185 DOMTypedArray* domTypedArray = |
| 1186 V8TypeOf<DOMTypedArray>::Type::toImplWithTypeCheck(isolate, value); |
| 1187 if (domTypedArray && domTypedArray->isShared()) { |
| 1188 exceptionState.throwTypeError( |
| 1189 "The provided ArrayBufferView value must not be shared."); |
| 1190 return NotSharedType(); |
| 1191 } |
| 1192 return NotSharedType(domTypedArray); |
| 1193 } |
| 1194 |
| 1162 } // namespace blink | 1195 } // namespace blink |
| 1163 | 1196 |
| 1164 #endif // V8Binding_h | 1197 #endif // V8Binding_h |
| OLD | NEW |