| OLD | NEW |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "V8Proxy.h" | 47 #include "V8Proxy.h" |
| 48 #include "WebKitFlags.h" | 48 #include "WebKitFlags.h" |
| 49 | 49 |
| 50 #include <wtf/text/AtomicString.h> | 50 #include <wtf/text/AtomicString.h> |
| 51 #include <wtf/text/CString.h> | 51 #include <wtf/text/CString.h> |
| 52 | 52 |
| 53 namespace WebCore { | 53 namespace WebCore { |
| 54 | 54 |
| 55 const char* DartUtilities::htmlLibraryName = "dart:html"; | 55 const char* DartUtilities::htmlLibraryName = "dart:html"; |
| 56 | 56 |
| 57 PassRefPtr<StringImpl> DartUtilities::toStringImpl(Dart_Handle object, Conversio
nFlag flag, Dart_Handle& exception) | 57 PassRefPtr<StringImpl> DartUtilities::toStringImpl(Dart_Handle object, Dart_Hand
le& exception) |
| 58 { | 58 { |
| 59 if (flag == ConvertNullToDefaultValue && Dart_IsNull(object)) | |
| 60 return 0; | |
| 61 | |
| 62 if (!Dart_IsString(object)) { | 59 if (!Dart_IsString(object)) { |
| 63 exception = Dart_NewString("String expected"); | 60 exception = Dart_NewString("String expected"); |
| 64 return 0; | 61 return 0; |
| 65 } | 62 } |
| 66 if (!Dart_IsString16(object)) { | 63 if (!Dart_IsString16(object)) { |
| 67 // FIXME: consider convertion to UTF16 in this case. | 64 // FIXME: consider convertion to UTF16 in this case. |
| 68 exception = Dart_NewString("32-bit string met, cannot be used in DOM API
"); | 65 exception = Dart_NewString("32-bit string met, cannot be used in DOM API
"); |
| 69 return 0; | 66 return 0; |
| 70 } | 67 } |
| 71 | 68 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return Dart_IntegerToInt64(object, value); | 125 return Dart_IntegerToInt64(object, value); |
| 129 // FIXME: support bigints. | 126 // FIXME: support bigints. |
| 130 } | 127 } |
| 131 }; | 128 }; |
| 132 | 129 |
| 133 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) | 130 int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) |
| 134 { | 131 { |
| 135 return convert<IntegerTrait>(object, exception); | 132 return convert<IntegerTrait>(object, exception); |
| 136 } | 133 } |
| 137 | 134 |
| 135 String DartUtilities::toString(Dart_Handle object) |
| 136 { |
| 137 Dart_Handle exception = 0; |
| 138 String string = dartToString(object, exception); |
| 139 ASSERT(!exception); |
| 140 return string; |
| 141 } |
| 142 |
| 138 struct DoubleTrait { | 143 struct DoubleTrait { |
| 139 typedef double nativeType; | 144 typedef double nativeType; |
| 140 static Dart_Handle convert(Dart_Handle object, double* value) | 145 static Dart_Handle convert(Dart_Handle object, double* value) |
| 141 { | 146 { |
| 142 if (!Dart_IsNumber(object)) | 147 if (!Dart_IsNumber(object)) |
| 143 return Dart_Error("the object !is Number"); | 148 return Dart_Error("the object !is Number"); |
| 144 | 149 |
| 145 if (!Dart_IsDouble(object)) { | 150 if (!Dart_IsDouble(object)) { |
| 146 object = Dart_Invoke(object, Dart_NewString("toDouble"), 0, 0); | 151 object = Dart_Invoke(object, Dart_NewString("toDouble"), 0, 0); |
| 147 if (Dart_IsError(object)) | 152 if (Dart_IsError(object)) |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 374 |
| 370 PassRefPtr<WebKitFlags> DartUtilities::toWebKitFlags(Dart_Handle object, Dart_Ha
ndle& exception) | 375 PassRefPtr<WebKitFlags> DartUtilities::toWebKitFlags(Dart_Handle object, Dart_Ha
ndle& exception) |
| 371 { | 376 { |
| 372 Vector<Dart_Handle> keys; | 377 Vector<Dart_Handle> keys; |
| 373 Vector<Dart_Handle> values; | 378 Vector<Dart_Handle> values; |
| 374 DartUtilities::extractMapElements(object, exception, keys, values); | 379 DartUtilities::extractMapElements(object, exception, keys, values); |
| 375 if (exception) | 380 if (exception) |
| 376 return 0; | 381 return 0; |
| 377 RefPtr<WebKitFlags> flags = WebKitFlags::create(); | 382 RefPtr<WebKitFlags> flags = WebKitFlags::create(); |
| 378 for (size_t i = 0; i < keys.size(); ++i) { | 383 for (size_t i = 0; i < keys.size(); ++i) { |
| 379 String key = DartUtilities::toStringImpl(keys[i], ConvertNone, exception
); | 384 String key = DartUtilities::dartToString(keys[i], exception); |
| 380 if (exception) | 385 if (exception) |
| 381 return 0; | 386 return 0; |
| 382 | 387 |
| 383 bool value = DartUtilities::dartToBool(values[i], exception); | 388 bool value = DartUtilities::dartToBool(values[i], exception); |
| 384 if (exception) | 389 if (exception) |
| 385 return 0; | 390 return 0; |
| 386 | 391 |
| 387 if (key == "create") | 392 if (key == "create") |
| 388 flags->setCreate(value); | 393 flags->setCreate(value); |
| 389 else if (key == "exclusive") | 394 else if (key == "exclusive") |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 errorMessage = internalErrorPrefix + Dart_GetError(result); | 551 errorMessage = internalErrorPrefix + Dart_GetError(result); |
| 547 else { | 552 else { |
| 548 // Print the exception. | 553 // Print the exception. |
| 549 Dart_Handle exception = Dart_ErrorGetException(result); | 554 Dart_Handle exception = Dart_ErrorGetException(result); |
| 550 ASSERT(!Dart_IsError(exception)); | 555 ASSERT(!Dart_IsError(exception)); |
| 551 | 556 |
| 552 exception = Dart_ToString(exception); | 557 exception = Dart_ToString(exception); |
| 553 if (Dart_IsError(exception)) | 558 if (Dart_IsError(exception)) |
| 554 errorMessage = String("Error converting exception to a string: ") +
Dart_GetError(exception); | 559 errorMessage = String("Error converting exception to a string: ") +
Dart_GetError(exception); |
| 555 else | 560 else |
| 556 errorMessage = String("Exception: ") + DartUtilities::dartStringToSt
ring(exception); | 561 errorMessage = String("Exception: ") + DartUtilities::toString(excep
tion); |
| 557 | 562 |
| 558 // FIXME: Fill in the callStack, sourceFile, and lineNumber | 563 // FIXME: Fill in the callStack, sourceFile, and lineNumber |
| 559 // and remove the below once the Dart APIs to iterate over the | 564 // and remove the below once the Dart APIs to iterate over the |
| 560 // trace are available. | 565 // trace are available. |
| 561 | 566 |
| 562 // Print the stack trace. | 567 // Print the stack trace. |
| 563 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(result); | 568 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(result); |
| 564 ASSERT(!Dart_IsError(stacktrace)); | 569 ASSERT(!Dart_IsError(stacktrace)); |
| 565 | 570 |
| 566 stacktrace = Dart_ToString(stacktrace); | 571 stacktrace = Dart_ToString(stacktrace); |
| 567 if (Dart_IsError(stacktrace)) | 572 if (Dart_IsError(stacktrace)) |
| 568 errorMessage += String("\nError converting stack trace to a string:
") + Dart_GetError(stacktrace); | 573 errorMessage += String("\nError converting stack trace to a string:
") + Dart_GetError(stacktrace); |
| 569 else | 574 else |
| 570 errorMessage += String("\nStack Trace: ") + DartUtilities::dartStrin
gToString(stacktrace); | 575 errorMessage += String("\nStack Trace: ") + DartUtilities::toString(
stacktrace); |
| 571 } | 576 } |
| 572 | 577 |
| 573 if (context && context->isDocument()) | 578 if (context && context->isDocument()) |
| 574 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe
r, sourceURL, callStack); | 579 static_cast<Document*>(context)->reportException(errorMessage, lineNumbe
r, sourceURL, callStack); |
| 575 } | 580 } |
| 576 | 581 |
| 577 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin
eNumber) | 582 Dart_Handle DartUtilities::notImplementedException(const char* fileName, int lin
eNumber) |
| 578 { | 583 { |
| 579 Dart_Handle args[2] = { Dart_NewString(fileName), Dart_NewInteger(lineNumber
) }; | 584 Dart_Handle args[2] = { Dart_NewString(fileName), Dart_NewInteger(lineNumber
) }; |
| 580 Dart_Handle result = DartUtilities::invokeUtilsMethod("makeNotImplementedExc
eption", 2, args); | 585 Dart_Handle result = DartUtilities::invokeUtilsMethod("makeNotImplementedExc
eption", 2, args); |
| 581 ASSERT(!Dart_IsError(result)); | 586 ASSERT(!Dart_IsError(result)); |
| 582 return result; | 587 return result; |
| 583 } | 588 } |
| 584 | 589 |
| 585 Dart_Handle DartUtilities::invokeUtilsMethod(const char* methodName, int argCoun
t, Dart_Handle* args) | 590 Dart_Handle DartUtilities::invokeUtilsMethod(const char* methodName, int argCoun
t, Dart_Handle* args) |
| 586 { | 591 { |
| 587 Dart_Handle library = htmlLibraryForCurrentIsolate(); | 592 Dart_Handle library = htmlLibraryForCurrentIsolate(); |
| 588 ASSERT(!Dart_IsError(library)); | 593 ASSERT(!Dart_IsError(library)); |
| 589 | 594 |
| 590 Dart_Handle utilsClass = Dart_GetClass(library, Dart_NewString("_Utils")); | 595 Dart_Handle utilsClass = Dart_GetClass(library, Dart_NewString("_Utils")); |
| 591 ASSERT(!Dart_IsError(utilsClass)); | 596 ASSERT(!Dart_IsError(utilsClass)); |
| 592 | 597 |
| 593 return Dart_Invoke(utilsClass, Dart_NewString(methodName), argCount, args); | 598 return Dart_Invoke(utilsClass, Dart_NewString(methodName), argCount, args); |
| 594 } | 599 } |
| 595 | 600 |
| 596 } | 601 } |
| OLD | NEW |