| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 v8SetReturnValueNull(callbackInfo); | 195 v8SetReturnValueNull(callbackInfo); |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) | 198 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) |
| 199 return; | 199 return; |
| 200 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap( | 200 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap( |
| 201 callbackInfo.GetIsolate(), callbackInfo.Holder()); | 201 callbackInfo.GetIsolate(), callbackInfo.Holder()); |
| 202 v8SetReturnValue(callbackInfo, wrapper); | 202 v8SetReturnValue(callbackInfo, wrapper); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Special versions for DOMWindow and EventTarget | |
| 206 | |
| 207 template <typename CallbackInfo> | |
| 208 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, | |
| 209 DOMWindow* impl) { | |
| 210 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 211 callbackInfo.GetIsolate())); | |
| 212 } | |
| 213 | |
| 214 template <typename CallbackInfo> | |
| 215 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, | |
| 216 EventTarget* impl) { | |
| 217 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 218 callbackInfo.GetIsolate())); | |
| 219 } | |
| 220 | |
| 221 template <typename CallbackInfo, typename T> | 205 template <typename CallbackInfo, typename T> |
| 222 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, | 206 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, |
| 223 PassRefPtr<T> impl) { | 207 PassRefPtr<T> impl) { |
| 224 v8SetReturnValue(callbackInfo, impl.get()); | 208 v8SetReturnValue(callbackInfo, impl.get()); |
| 225 } | 209 } |
| 226 | 210 |
| 227 template <typename CallbackInfo> | 211 template <typename CallbackInfo> |
| 228 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, | 212 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, |
| 229 ScriptWrappable* impl) { | 213 ScriptWrappable* impl) { |
| 230 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); | 214 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); |
| 231 if (UNLIKELY(!impl)) { | 215 if (UNLIKELY(!impl)) { |
| 232 v8SetReturnValueNull(callbackInfo); | 216 v8SetReturnValueNull(callbackInfo); |
| 233 return; | 217 return; |
| 234 } | 218 } |
| 235 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(), | 219 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(), |
| 236 impl)) | 220 impl)) |
| 237 return; | 221 return; |
| 238 v8::Local<v8::Object> wrapper = | 222 v8::Local<v8::Object> wrapper = |
| 239 impl->wrap(callbackInfo.GetIsolate(), callbackInfo.Holder()); | 223 impl->wrap(callbackInfo.GetIsolate(), callbackInfo.Holder()); |
| 240 v8SetReturnValue(callbackInfo, wrapper); | 224 v8SetReturnValue(callbackInfo, wrapper); |
| 241 } | 225 } |
| 242 | 226 |
| 243 template <typename CallbackInfo> | |
| 244 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, | |
| 245 Node* impl) { | |
| 246 // Since EventTarget has a special version of ToV8 and V8EventTarget.h | |
| 247 // defines its own v8SetReturnValue family, which are slow, we need to | |
| 248 // override them with optimized versions for Node and its subclasses. | |
| 249 // Without this overload, v8SetReturnValueForMainWorld for Node would be | |
| 250 // very slow. | |
| 251 // | |
| 252 // class hierarchy: | |
| 253 // ScriptWrappable <-- EventTarget <--+-- Node <-- ... | |
| 254 // +-- Window | |
| 255 // overloads: | |
| 256 // v8SetReturnValueForMainWorld(ScriptWrappable*) | |
| 257 // Optimized and very fast. | |
| 258 // v8SetReturnValueForMainWorld(EventTarget*) | |
| 259 // Uses custom toV8 function and slow. | |
| 260 // v8SetReturnValueForMainWorld(Node*) | |
| 261 // Optimized and very fast. | |
| 262 // v8SetReturnValueForMainWorld(Window*) | |
| 263 // Uses custom toV8 function and slow. | |
| 264 v8SetReturnValueForMainWorld(callbackInfo, ScriptWrappable::fromNode(impl)); | |
| 265 } | |
| 266 | |
| 267 // Special versions for DOMWindow and EventTarget | |
| 268 | |
| 269 template <typename CallbackInfo> | |
| 270 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, | |
| 271 DOMWindow* impl) { | |
| 272 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 273 callbackInfo.GetIsolate())); | |
| 274 } | |
| 275 | |
| 276 template <typename CallbackInfo> | |
| 277 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, | |
| 278 EventTarget* impl) { | |
| 279 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 280 callbackInfo.GetIsolate())); | |
| 281 } | |
| 282 | |
| 283 template <typename CallbackInfo, typename T> | 227 template <typename CallbackInfo, typename T> |
| 284 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, | 228 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, |
| 285 PassRefPtr<T> impl) { | 229 PassRefPtr<T> impl) { |
| 286 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); | 230 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); |
| 287 } | 231 } |
| 288 | 232 |
| 289 template <typename CallbackInfo> | 233 template <typename CallbackInfo> |
| 290 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, | 234 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, |
| 291 ScriptWrappable* impl, | 235 ScriptWrappable* impl, |
| 292 const ScriptWrappable* wrappable) { | 236 const ScriptWrappable* wrappable) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 311 return; | 255 return; |
| 312 } | 256 } |
| 313 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, | 257 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, |
| 314 callbackInfo.Holder(), wrappable)) | 258 callbackInfo.Holder(), wrappable)) |
| 315 return; | 259 return; |
| 316 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap( | 260 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap( |
| 317 callbackInfo.GetIsolate(), callbackInfo.Holder()); | 261 callbackInfo.GetIsolate(), callbackInfo.Holder()); |
| 318 v8SetReturnValue(callbackInfo, wrapper); | 262 v8SetReturnValue(callbackInfo, wrapper); |
| 319 } | 263 } |
| 320 | 264 |
| 321 // Special versions for DOMWindow and EventTarget | |
| 322 | |
| 323 template <typename CallbackInfo> | |
| 324 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, | |
| 325 DOMWindow* impl, | |
| 326 const ScriptWrappable*) { | |
| 327 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 328 callbackInfo.GetIsolate())); | |
| 329 } | |
| 330 | |
| 331 template <typename CallbackInfo> | |
| 332 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, | |
| 333 EventTarget* impl, | |
| 334 const ScriptWrappable*) { | |
| 335 v8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), | |
| 336 callbackInfo.GetIsolate())); | |
| 337 } | |
| 338 | |
| 339 template <typename CallbackInfo, typename T, typename Wrappable> | 265 template <typename CallbackInfo, typename T, typename Wrappable> |
| 340 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, | 266 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, |
| 341 PassRefPtr<T> impl, | 267 PassRefPtr<T> impl, |
| 342 const Wrappable* wrappable) { | 268 const Wrappable* wrappable) { |
| 343 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); | 269 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); |
| 344 } | 270 } |
| 345 | 271 |
| 346 template <typename CallbackInfo, typename T> | 272 template <typename CallbackInfo, typename T> |
| 347 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, | 273 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, |
| 348 const v8::Local<T> handle, | 274 const v8::Local<T> handle, |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 // If the argument isn't an object, this will crash. | 1087 // If the argument isn't an object, this will crash. |
| 1162 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, | 1088 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, |
| 1163 v8::Isolate*); | 1089 v8::Isolate*); |
| 1164 | 1090 |
| 1165 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, | 1091 CORE_EXPORT v8::Local<v8::Value> fromJSONString(v8::Isolate*, |
| 1166 const String& stringifiedJSON, | 1092 const String& stringifiedJSON, |
| 1167 ExceptionState&); | 1093 ExceptionState&); |
| 1168 } // namespace blink | 1094 } // namespace blink |
| 1169 | 1095 |
| 1170 #endif // V8Binding_h | 1096 #endif // V8Binding_h |
| OLD | NEW |