| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 { | 45 { |
| 46 DartApiScope dartApiScope; | 46 DartApiScope dartApiScope; |
| 47 Dart_Handle exception = 0; | 47 Dart_Handle exception = 0; |
| 48 { | 48 { |
| 49 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext(
); | 49 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext(
); |
| 50 if (!context) { | 50 if (!context) { |
| 51 exception = Dart_NewString("WebSocket constructor's associated conte
xt is not available"); | 51 exception = Dart_NewString("WebSocket constructor's associated conte
xt is not available"); |
| 52 goto fail; | 52 goto fail; |
| 53 } | 53 } |
| 54 | 54 |
| 55 const ParameterAdapter<String> url(Dart_GetNativeArgument(args, 0)); | 55 DartStringAdapter url = DartUtilities::dartToString(Dart_GetNativeArgume
nt(args, 0), exception); |
| 56 if (!url.conversionSuccessful()) { | 56 if (exception) |
| 57 exception = url.exception(); | |
| 58 goto fail; | 57 goto fail; |
| 59 } | |
| 60 | 58 |
| 61 const KURL& absoluteURL = context->completeURL(url); | 59 const KURL& absoluteURL = context->completeURL(url); |
| 62 | 60 |
| 63 RefPtr<WebSocket> receiver = WebSocket::create(context); | 61 RefPtr<WebSocket> receiver = WebSocket::create(context); |
| 64 ExceptionCode ec = 0; | 62 ExceptionCode ec = 0; |
| 65 receiver->connect(absoluteURL, ec); | 63 receiver->connect(absoluteURL, ec); |
| 66 if (UNLIKELY(ec)) { | 64 if (UNLIKELY(ec)) { |
| 67 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | 65 exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
| 68 goto fail; | 66 goto fail; |
| 69 } | 67 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 ArrayBuffer* data = DartArrayBuffer::toNative(dataHandle, exception)
; | 90 ArrayBuffer* data = DartArrayBuffer::toNative(dataHandle, exception)
; |
| 93 if (exception) | 91 if (exception) |
| 94 goto fail; | 92 goto fail; |
| 95 result = receiver->send(data, ec); | 93 result = receiver->send(data, ec); |
| 96 } else if (DartDOMWrapper::instanceOf<DartBlob>(dataHandle)) { | 94 } else if (DartDOMWrapper::instanceOf<DartBlob>(dataHandle)) { |
| 97 Blob* data = DartBlob::toNative(dataHandle, exception); | 95 Blob* data = DartBlob::toNative(dataHandle, exception); |
| 98 if (exception) | 96 if (exception) |
| 99 goto fail; | 97 goto fail; |
| 100 result = receiver->send(data, ec); | 98 result = receiver->send(data, ec); |
| 101 } else if (Dart_IsString(dataHandle)) { | 99 } else if (Dart_IsString(dataHandle)) { |
| 102 const ParameterAdapter<String> data(dataHandle); | 100 DartStringAdapter data = DartUtilities::dartToString(dataHandle, exc
eption); |
| 103 if (!data.conversionSuccessful()) { | 101 if (exception) |
| 104 exception = data.exception(); | |
| 105 goto fail; | 102 goto fail; |
| 106 } | |
| 107 result = receiver->send(data, ec); | 103 result = receiver->send(data, ec); |
| 108 } else { | 104 } else { |
| 109 exception = Dart_NewString("Unsupported data argument type"); | 105 exception = Dart_NewString("Unsupported data argument type"); |
| 110 goto fail; | 106 goto fail; |
| 111 } | 107 } |
| 112 | 108 |
| 113 if (UNLIKELY(ec)) { | 109 if (UNLIKELY(ec)) { |
| 114 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | 110 exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
| 115 goto fail; | 111 goto fail; |
| 116 } | 112 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 144 fail: | 140 fail: |
| 145 Dart_ThrowException(exception); | 141 Dart_ThrowException(exception); |
| 146 ASSERT_NOT_REACHED(); | 142 ASSERT_NOT_REACHED(); |
| 147 } | 143 } |
| 148 | 144 |
| 149 } | 145 } |
| 150 | 146 |
| 151 } | 147 } |
| 152 | 148 |
| 153 #endif // ENABLE(WEB_SOCKETS) | 149 #endif // ENABLE(WEB_SOCKETS) |
| OLD | NEW |