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

Side by Side Diff: Source/bindings/dart/DartUtilities.cpp

Issue 24677002: Revert "Revert "Dartium changes for custom element lifecycle events."" (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011, Google Inc. 1 // Copyright 2011, Google Inc.
2 // All rights reserved. 2 // 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 are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * 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 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "bindings/dart/DartUtilities.h" 31 #include "bindings/dart/DartUtilities.h"
32 32
33 #include "DartBlob.h"
34 #include "DartIDBKeyRange.h"
35 #include "DartImageData.h"
33 #include "DartMessagePort.h" 36 #include "DartMessagePort.h"
34 #include "bindings/dart/DartDOMData.h" 37 #include "bindings/dart/DartDOMData.h"
35 #include "bindings/dart/DartHandleProxy.h" 38 #include "bindings/dart/DartHandleProxy.h"
36 #include "bindings/dart/V8Converter.h" 39 #include "bindings/dart/V8Converter.h"
37 #include "bindings/v8/ScriptController.h" 40 #include "bindings/v8/ScriptController.h"
38 #include "bindings/v8/SerializedScriptValue.h" 41 #include "bindings/v8/SerializedScriptValue.h"
39 #include "core/dom/Document.h" 42 #include "core/dom/Document.h"
40 #include "core/html/canvas/DataView.h" 43 #include "core/html/canvas/DataView.h"
41 #include "core/inspector/ScriptArguments.h" 44 #include "core/inspector/ScriptArguments.h"
42 #include "core/inspector/ScriptCallStack.h" 45 #include "core/inspector/ScriptCallStack.h"
(...skipping 15 matching lines...) Expand all
58 #include <wtf/Uint8Array.h> 61 #include <wtf/Uint8Array.h>
59 #include <wtf/Uint8ClampedArray.h> 62 #include <wtf/Uint8ClampedArray.h>
60 #include <wtf/text/AtomicString.h> 63 #include <wtf/text/AtomicString.h>
61 #include <wtf/text/CString.h> 64 #include <wtf/text/CString.h>
62 #include <wtf/text/WTFString.h> 65 #include <wtf/text/WTFString.h>
63 66
64 namespace WebCore { 67 namespace WebCore {
65 68
66 const char* DartUtilities::htmlLibraryName = "dart:html"; 69 const char* DartUtilities::htmlLibraryName = "dart:html";
67 const char* DartUtilities::indexedDBLibraryName = "dart:indexed_db"; 70 const char* DartUtilities::indexedDBLibraryName = "dart:indexed_db";
71 const char* DartUtilities::svgLibraryName = "dart:svg";
68 72
69 static void stringFinalizer(void* peer) 73 static void stringFinalizer(void* peer)
70 { 74 {
71 reinterpret_cast<StringImpl*>(peer)->deref(); 75 reinterpret_cast<StringImpl*>(peer)->deref();
72 } 76 }
73 77
74 template <typename T> PassRefPtr<StringImpl> convertAndExternalize(Dart_Handle s tring, intptr_t length) 78 template <typename T> PassRefPtr<StringImpl> convertAndExternalize(Dart_Handle s tring, intptr_t length)
75 { 79 {
76 if (!length) 80 if (!length)
77 return StringImpl::empty(); 81 return StringImpl::empty();
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 return dartToDate(object, exception); 342 return dartToDate(object, exception);
339 } 343 }
340 344
341 bool DartUtilities::isDateTime(Dart_Handle handle) 345 bool DartUtilities::isDateTime(Dart_Handle handle)
342 { 346 {
343 return objectIsType(handle, "dart:core", "DateTime"); 347 return objectIsType(handle, "dart:core", "DateTime");
344 } 348 }
345 349
346 bool DartUtilities::isBlob(Dart_Handle handle) 350 bool DartUtilities::isBlob(Dart_Handle handle)
347 { 351 {
348 return objectIsType(handle, htmlLibraryName, "Blob"); 352 return objectIsClass(handle, DartDOMWrapper::dartClass<DartBlob>());
349 } 353 }
350 354
351 bool DartUtilities::isImageData(Dart_Handle handle) 355 bool DartUtilities::isImageData(Dart_Handle handle)
352 { 356 {
353 return objectIsType(handle, htmlLibraryName, "ImageData"); 357 return objectIsClass(handle, DartDOMWrapper::dartClass<DartImageData>());
354 } 358 }
355 359
356 bool DartUtilities::isIDBKeyRange(Dart_Handle handle) 360 bool DartUtilities::isIDBKeyRange(Dart_Handle handle)
357 { 361 {
358 return objectIsType(handle, indexedDBLibraryName, "KeyRange"); 362 return objectIsClass(handle, DartDOMWrapper::dartClass<DartIDBKeyRange>());
363 }
364
365 bool DartUtilities::objectIsClass(Dart_Handle handle, Dart_Handle cls)
vsm 2013/09/25 22:39:10 I'd call this objectIsType for clarity.
blois 2013/09/25 22:50:18 Done.
366 {
367 bool isType = false;
368 Dart_Handle result = Dart_ObjectIsType(handle, cls, &isType);
369 ASSERT(!Dart_IsError(result));
370 if (Dart_IsError(result))
371 return false;
372
373 return isType;
359 } 374 }
360 375
361 bool DartUtilities::objectIsType(Dart_Handle handle, const char* libraryName, co nst char* typeName) 376 bool DartUtilities::objectIsType(Dart_Handle handle, const char* libraryName, co nst char* typeName)
362 { 377 {
363 // FIXME: cache the lookup for library & type name. 378 // FIXME: cache the lookup for library & type name.
364 Dart_Handle library = libraryForCurrentIsolate(libraryName); 379 Dart_Handle library = libraryForCurrentIsolate(libraryName);
365 ASSERT(!Dart_IsError(library)); 380 ASSERT(!Dart_IsError(library));
366 381
367 Dart_Handle cls = Dart_GetClass(library, Dart_NewStringFromCString(typeName) ); 382 Dart_Handle cls = Dart_GetClass(library, Dart_NewStringFromCString(typeName) );
368 ASSERT(!Dart_IsError(cls)); 383 ASSERT(!Dart_IsError(cls));
369 384
370 bool isType = false; 385 bool isType = false;
vsm 2013/09/25 22:39:10 Can you modify this to call the above function ins
blois 2013/09/25 22:50:18 Done.
371 Dart_Handle result = Dart_ObjectIsType(handle, cls, &isType); 386 Dart_Handle result = Dart_ObjectIsType(handle, cls, &isType);
372 ASSERT(!Dart_IsError(result)); 387 ASSERT(!Dart_IsError(result));
373 if (Dart_IsError(result)) 388 if (Dart_IsError(result))
374 return false; 389 return false;
375 390
376 return isType; 391 return isType;
377 } 392 }
378 393
394 bool DartUtilities::isTypeSubclassOf(Dart_Handle type, const char* libraryName, const char* typeName)
395 {
396 Dart_Handle library = libraryForCurrentIsolate(libraryName);
397 ASSERT(!Dart_IsError(library));
398
399 Dart_Handle other = Dart_GetType(library, Dart_NewStringFromCString(typeName ), 0, 0);
400 ASSERT(!Dart_IsError(other));
401
402 Dart_Handle args[2] = { type, other };
403 Dart_Handle result = DartUtilities::invokeUtilsMethod("isTypeSubclassOf", 2, args);
404 ASSERT(!Dart_IsError(result));
405 if (Dart_IsError(result))
406 return false;
407
408 Dart_Handle exception = 0;
409 bool boolResult = dartToBool(result, exception);
410 if (exception)
411 return false;
412 return boolResult;
413 }
414
379 bool DartUtilities::isTypedData(Dart_Handle handle) 415 bool DartUtilities::isTypedData(Dart_Handle handle)
380 { 416 {
381 return Dart_GetTypeOfTypedData(handle) != Dart_TypedData_kInvalid || Dart_Ge tTypeOfExternalTypedData(handle) != Dart_TypedData_kInvalid; 417 return Dart_GetTypeOfTypedData(handle) != Dart_TypedData_kInvalid || Dart_Ge tTypeOfExternalTypedData(handle) != Dart_TypedData_kInvalid;
382 } 418 }
383 419
384 static Dart_TypedData_Type typedDataTypeFromViewType(ArrayBufferView::ViewType t ype) 420 static Dart_TypedData_Type typedDataTypeFromViewType(ArrayBufferView::ViewType t ype)
385 { 421 {
386 switch (type) { 422 switch (type) {
387 case ArrayBufferView::TypeInt8: 423 case ArrayBufferView::TypeInt8:
388 return Dart_TypedData_kInt8; 424 return Dart_TypedData_kInt8;
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 Dart_Handle library = htmlLibraryForCurrentIsolate(); 1062 Dart_Handle library = htmlLibraryForCurrentIsolate();
1027 ASSERT(!Dart_IsError(library)); 1063 ASSERT(!Dart_IsError(library));
1028 1064
1029 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0); 1065 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0);
1030 ASSERT(!Dart_IsError(utilsClass)); 1066 ASSERT(!Dart_IsError(utilsClass));
1031 1067
1032 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args); 1068 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args);
1033 } 1069 }
1034 1070
1035 } 1071 }
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartUtilities.h ('k') | Source/bindings/dart/custom/DartDocumentCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698