OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "bindings/core/dart/V8Converter.h" |
| 33 |
| 34 #include "bindings/core/v8/V8Blob.h" |
| 35 #include "bindings/core/v8/V8DOMStringList.h" |
| 36 #include "bindings/core/v8/V8Event.h" |
| 37 #include "bindings/core/v8/V8ImageData.h" |
| 38 #include "bindings/core/v8/V8Node.h" |
| 39 #include "bindings/core/v8/V8Window.h" |
| 40 #include "bindings/core/dart/DartUtilities.h" |
| 41 #include "bindings/modules/v8/V8IDBCursor.h" |
| 42 #include "bindings/modules/v8/V8IDBCursorWithValue.h" |
| 43 #include "bindings/modules/v8/V8IDBDatabase.h" |
| 44 #include "bindings/modules/v8/V8IDBFactory.h" |
| 45 #include "bindings/modules/v8/V8IDBKeyRange.h" |
| 46 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" |
| 47 #include "bindings/core/v8/custom/V8DataViewCustom.h" |
| 48 #include "bindings/core/v8/custom/V8Float32ArrayCustom.h" |
| 49 #include "bindings/core/v8/custom/V8Float64ArrayCustom.h" |
| 50 #include "bindings/core/v8/custom/V8Int16ArrayCustom.h" |
| 51 #include "bindings/core/v8/custom/V8Int32ArrayCustom.h" |
| 52 #include "bindings/core/v8/custom/V8Int8ArrayCustom.h" |
| 53 #include "bindings/core/v8/custom/V8TypedArrayCustom.h" |
| 54 #include "bindings/core/v8/custom/V8Uint16ArrayCustom.h" |
| 55 #include "bindings/core/v8/custom/V8Uint32ArrayCustom.h" |
| 56 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h" |
| 57 #include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h" |
| 58 |
| 59 #include "wtf/Vector.h" |
| 60 |
| 61 #include <utility> |
| 62 |
| 63 namespace blink { |
| 64 |
| 65 class DartToV8Map { |
| 66 public: |
| 67 DartToV8Map() |
| 68 : m_list() |
| 69 { |
| 70 } |
| 71 |
| 72 v8::Handle<v8::Value> get(Dart_Handle key) |
| 73 { |
| 74 for (size_t i = 0; i < m_list.size(); ++i) { |
| 75 if (Dart_IdentityEquals(key, m_list[i].first)) |
| 76 return m_list[i].second; |
| 77 } |
| 78 return v8::Handle<v8::Value>(); |
| 79 } |
| 80 |
| 81 v8::Handle<v8::Value> put(Dart_Handle key, v8::Handle<v8::Value> value) |
| 82 { |
| 83 ASSERT(!value.IsEmpty()); |
| 84 ASSERT(get(key).IsEmpty()); |
| 85 m_list.append(std::make_pair(key, value)); |
| 86 return value; |
| 87 } |
| 88 |
| 89 private: |
| 90 Vector< std::pair< Dart_Handle, v8::Handle<v8::Value> > > m_list; |
| 91 }; |
| 92 |
| 93 class V8ToDartMap { |
| 94 public: |
| 95 V8ToDartMap() |
| 96 : m_list() |
| 97 { |
| 98 } |
| 99 |
| 100 Dart_Handle get(v8::Handle<v8::Value> key) |
| 101 { |
| 102 for (size_t i = 0; i < m_list.size(); ++i) { |
| 103 if (m_list[i].first == key) |
| 104 return m_list[i].second; |
| 105 } |
| 106 return 0; |
| 107 } |
| 108 |
| 109 Dart_Handle put(v8::Handle<v8::Value> key, Dart_Handle value) |
| 110 { |
| 111 ASSERT(!get(key)); |
| 112 m_list.append(std::make_pair(key, value)); |
| 113 return value; |
| 114 } |
| 115 |
| 116 private: |
| 117 Vector< std::pair<v8::Handle<v8::Value> , Dart_Handle> > m_list; |
| 118 }; |
| 119 |
| 120 v8::Handle<v8::Value> V8Converter::toV8IfPrimitive(DartDOMData* domData, Dart_Ha
ndle value, Dart_Handle& exception) |
| 121 { |
| 122 if (Dart_IsNull(value)) |
| 123 return v8::Null(v8::Isolate::GetCurrent()); |
| 124 if (Dart_IsString(value)) |
| 125 return stringToV8(value); |
| 126 if (Dart_IsBoolean(value)) |
| 127 return booleanToV8(value); |
| 128 if (Dart_IsNumber(value)) |
| 129 return numberToV8(value, exception); |
| 130 if (DartUtilities::isDateTime(domData, value)) |
| 131 return dateToV8(value, exception); |
| 132 |
| 133 return v8::Handle<v8::Value>(); |
| 134 } |
| 135 |
| 136 v8::Handle<v8::Value> V8Converter::toV8IfBrowserNative(DartDOMData* domData, Dar
t_Handle value, Dart_Handle& exception) |
| 137 { |
| 138 if (Dart_IsByteBuffer(value)) { |
| 139 Dart_Handle data = Dart_GetDataFromByteBuffer(value); |
| 140 return arrayBufferToV8(data, exception); |
| 141 } |
| 142 if (Dart_IsTypedData(value)) |
| 143 return arrayBufferToV8(value, exception); |
| 144 // TODO(terry): Using JS Interop only arrays are converted. |
| 145 /* |
| 146 if (DartDOMWrapper::subtypeOf(value, DartBlob::dartClassId)) |
| 147 return blobToV8(value, exception); |
| 148 if (DartDOMWrapper::subtypeOf(value, DartImageData::dartClassId)) |
| 149 return imageDataToV8(value, exception); |
| 150 if (DartDOMWrapper::subtypeOf(value, DartIDBKeyRange::dartClassId)) |
| 151 return idbKeyRangeToV8(value, exception); |
| 152 if (DartDOMWrapper::subtypeOf(value, DartDOMStringList::dartClassId)) |
| 153 return domStringListToV8(value, exception); |
| 154 if (DartDOMWrapper::subtypeOf(value, DartNode::dartClassId)) |
| 155 return nodeToV8(value, exception); |
| 156 if (DartDOMWrapper::subtypeOf(value, DartEvent::dartClassId)) |
| 157 return eventToV8(value, exception); |
| 158 if (DartDOMWrapper::subtypeOf(value, DartWindow::dartClassId)) |
| 159 return windowToV8(value, exception); |
| 160 */ |
| 161 return v8::Handle<v8::Value>(); |
| 162 } |
| 163 |
| 164 v8::Handle<v8::Value> V8Converter::toV8(Dart_Handle value, DartToV8Map& map, Dar
t_Handle& exception) |
| 165 { |
| 166 v8::Handle<v8::Value> result = map.get(value); |
| 167 if (!result.IsEmpty()) |
| 168 return result; |
| 169 |
| 170 DartDOMData* domData = DartDOMData::current(); |
| 171 |
| 172 result = toV8IfPrimitive(domData, value, exception); |
| 173 if (!result.IsEmpty()) |
| 174 return result; |
| 175 |
| 176 // ArrayBuffer{,View} checks in toV8IfBrowserNative must go before IsList |
| 177 // check as they implement list. |
| 178 result = toV8IfBrowserNative(domData, value, exception); |
| 179 if (!result.IsEmpty()) { |
| 180 map.put(value, result); |
| 181 return result; |
| 182 } |
| 183 |
| 184 if (Dart_IsList(value)) |
| 185 return listToV8(value, map, exception); |
| 186 |
| 187 bool isMap = DartUtilities::dartToBool(DartUtilities::invokeUtilsMethod("isM
ap", 1, &value), exception); |
| 188 ASSERT(!exception); |
| 189 if (isMap) |
| 190 return mapToV8(value, map, exception); |
| 191 |
| 192 exception = Dart_NewStringFromCString("unsupported object type for conversio
n"); |
| 193 return v8::Handle<v8::Value>(); |
| 194 } |
| 195 |
| 196 v8::Handle<v8::Value> V8Converter::toV8(Dart_Handle value, Dart_Handle& exceptio
n) |
| 197 { |
| 198 DartToV8Map map; |
| 199 return toV8(value, map, exception); |
| 200 } |
| 201 |
| 202 Dart_Handle V8Converter::toDartIfPrimitive(v8::Handle<v8::Value> value) |
| 203 { |
| 204 if (value->IsUndefined()) |
| 205 return Dart_Null(); |
| 206 if (value->IsNull()) |
| 207 return Dart_Null(); |
| 208 if (value->IsString()) |
| 209 return stringToDart(value); |
| 210 if (value->IsNumber()) |
| 211 return DartUtilities::numberToDart(value->NumberValue()); |
| 212 if (value->IsBoolean()) |
| 213 return Dart_NewBoolean(value->BooleanValue()); |
| 214 if (value->IsDate()) |
| 215 return dateToDart(value); |
| 216 return 0; |
| 217 } |
| 218 |
| 219 /** |
| 220 * Convert a subset of types that are backed by browser native objects. |
| 221 * These are types that can be passed transparently between Dart and JS |
| 222 * with the dart:js interop library. |
| 223 */ |
| 224 Dart_Handle V8Converter::toDartIfBrowserNative(v8::Handle<v8::Object> object, v8
::Isolate* isolate, Dart_Handle& exception) |
| 225 { |
| 226 if (V8ArrayBuffer::hasInstance(object, isolate)) |
| 227 return arrayBufferToDart(object, exception); |
| 228 if (V8ArrayBufferView::hasInstance(object, isolate)) |
| 229 return arrayBufferViewToDart(object, exception); |
| 230 // TODO(terry): Using JS Interop only arrays are converted. |
| 231 /* |
| 232 if (V8Blob::hasInstance(object, isolate)) |
| 233 return blobToDart(object, exception); |
| 234 if (V8DOMStringList::hasInstance(object, isolate)) |
| 235 return domStringListToDart(object, exception); |
| 236 if (V8ImageData::hasInstance(object, isolate)) |
| 237 return imageDataToDart(object, exception); |
| 238 if (V8IDBKeyRange::hasInstance(object, isolate)) |
| 239 return idbKeyRangeToDart(object, exception); |
| 240 if (V8IDBDatabase::hasInstance(object, isolate)) |
| 241 return idbDatabaseToDart(object, exception); |
| 242 if (V8IDBFactory::hasInstance(object, isolate)) |
| 243 return idbFactoryToDart(object, exception); |
| 244 if (V8IDBCursorWithValue::hasInstance(object, isolate)) |
| 245 return idbCursorWithValueToDart(object, exception); |
| 246 if (V8IDBCursor::hasInstance(object, isolate)) |
| 247 return idbCursorToDart(object, exception); |
| 248 if (V8Node::hasInstance(object, isolate)) { |
| 249 // FIXME(jacobr): there has to be a faster way to perform this check. |
| 250 if (!object->CreationContext()->Global()->StrictEquals(DartUtilities::cu
rrentV8Context()->Global())) { |
| 251 // The window is from a different context so do not convert. |
| 252 return 0; |
| 253 } |
| 254 return nodeToDart(object); |
| 255 } |
| 256 if (V8Event::hasInstance(object, isolate)) { |
| 257 // FIXME(jacobr): there has to be a faster way to perform this check. |
| 258 if (!object->CreationContext()->Global()->StrictEquals(DartUtilities::cu
rrentV8Context()->Global())) { |
| 259 // The window is from a different context so do not convert. |
| 260 return 0; |
| 261 } |
| 262 return eventToDart(object); |
| 263 } |
| 264 |
| 265 v8::Handle<v8::Object> window = object->FindInstanceInPrototypeChain(V8Windo
w::domTemplate(isolate)); |
| 266 if (!window.IsEmpty()) { |
| 267 // FIXME(jacobr): there has to be a faster way to perform this check. |
| 268 if (!object->CreationContext()->Global()->StrictEquals(DartUtilities::cu
rrentV8Context()->Global())) { |
| 269 // The window is from a different context so do not convert. |
| 270 return 0; |
| 271 } |
| 272 return windowToDart(window); |
| 273 } |
| 274 */ |
| 275 return 0; |
| 276 } |
| 277 |
| 278 Dart_Handle V8Converter::toDart(v8::Handle<v8::Value> value, V8ToDartMap& map, D
art_Handle& exception) |
| 279 { |
| 280 Dart_Handle result = map.get(value); |
| 281 if (result) |
| 282 return result; |
| 283 |
| 284 result = toDartIfPrimitive(value); |
| 285 if (result) |
| 286 return result; |
| 287 |
| 288 if (value->IsArray()) |
| 289 return listToDart(value.As<v8::Array>(), map, exception); |
| 290 if (value->IsObject()) { |
| 291 v8::Handle<v8::Object> object = value.As<v8::Object>(); |
| 292 v8::Isolate* isolate = object->CreationContext()->GetIsolate(); |
| 293 |
| 294 result = toDartIfBrowserNative(object, isolate, exception); |
| 295 if (result) { |
| 296 map.put(object, result); |
| 297 return result; |
| 298 } |
| 299 return mapToDart(object, map, exception); |
| 300 } |
| 301 |
| 302 // FIXME: support other types. |
| 303 exception = Dart_NewStringFromCString("unsupported object type for conversio
n"); |
| 304 return 0; |
| 305 } |
| 306 |
| 307 Dart_Handle V8Converter::toDart(v8::Handle<v8::Value> value, Dart_Handle& except
ion) |
| 308 { |
| 309 V8ToDartMap map; |
| 310 return toDart(value, map, exception); |
| 311 } |
| 312 |
| 313 v8::Handle<v8::String> V8Converter::stringToV8(Dart_Handle value) |
| 314 { |
| 315 ASSERT(Dart_IsString(value)); |
| 316 uint8_t* data = 0; |
| 317 intptr_t length = -1; |
| 318 Dart_Handle ALLOW_UNUSED result = Dart_StringToUTF8(value, &data, &length); |
| 319 ASSERT(!Dart_IsError(result)); |
| 320 return v8::String::NewFromUtf8( |
| 321 v8::Isolate::GetCurrent(), reinterpret_cast<const char*>(data), |
| 322 v8::String::kNormalString, length); |
| 323 } |
| 324 |
| 325 Dart_Handle V8Converter::stringToDart(v8::Handle<v8::Value> value) |
| 326 { |
| 327 ASSERT(value->IsString()); |
| 328 v8::String::Utf8Value stringValue(value); |
| 329 const char* data = *stringValue; |
| 330 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(data), string
Value.length()); |
| 331 } |
| 332 |
| 333 v8::Handle<v8::Value> V8Converter::booleanToV8(Dart_Handle value) |
| 334 { |
| 335 ASSERT(Dart_IsBoolean(value)); |
| 336 bool booleanValue; |
| 337 Dart_Handle ALLOW_UNUSED result = Dart_BooleanValue(value, &booleanValue); |
| 338 ASSERT(!Dart_IsError(result)); |
| 339 return v8::Boolean::New(v8::Isolate::GetCurrent(), booleanValue); |
| 340 } |
| 341 |
| 342 v8::Handle<v8::Value> V8Converter::numberToV8(Dart_Handle value) |
| 343 { |
| 344 Dart_Handle exception = 0; |
| 345 v8::Handle<v8::Value> result = numberToV8(value, exception); |
| 346 ASSERT(!exception); |
| 347 return result; |
| 348 } |
| 349 |
| 350 v8::Handle<v8::Value> V8Converter::numberToV8(Dart_Handle value, Dart_Handle& ex
ception) |
| 351 { |
| 352 ASSERT(Dart_IsNumber(value)); |
| 353 |
| 354 double asDouble = DartUtilities::dartToDouble(value, exception); |
| 355 if (exception) |
| 356 return v8::Undefined(v8::Isolate::GetCurrent()); |
| 357 return v8::Number::New(v8::Isolate::GetCurrent(), asDouble); |
| 358 } |
| 359 |
| 360 v8::Handle<v8::Value> V8Converter::listToV8(Dart_Handle value) |
| 361 { |
| 362 DartToV8Map map; |
| 363 Dart_Handle exception = 0; |
| 364 v8::Handle<v8::Value> result = listToV8(value, map, exception); |
| 365 ASSERT(!exception); |
| 366 return result; |
| 367 } |
| 368 |
| 369 v8::Handle<v8::Value> V8Converter::listToV8(Dart_Handle value, DartToV8Map& map,
Dart_Handle& exception) |
| 370 { |
| 371 ASSERT(Dart_IsList(value)); |
| 372 |
| 373 intptr_t length = 0; |
| 374 Dart_Handle result = Dart_ListLength(value, &length); |
| 375 if (!DartUtilities::checkResult(result, exception)) |
| 376 return v8::Handle<v8::Value>(); |
| 377 |
| 378 v8::Local<v8::Array> array = v8::Array::New(v8::Isolate::GetCurrent(), lengt
h); |
| 379 map.put(value, array); |
| 380 |
| 381 for (intptr_t i = 0; i < length; ++i) { |
| 382 result = Dart_ListGetAt(value, i); |
| 383 if (!DartUtilities::checkResult(result, exception)) |
| 384 return v8::Handle<v8::Value>(); |
| 385 v8::Handle<v8::Value> v8value = toV8(result, map, exception); |
| 386 if (exception) |
| 387 return v8::Handle<v8::Value>(); |
| 388 array->Set(i, v8value); |
| 389 } |
| 390 |
| 391 return array; |
| 392 } |
| 393 |
| 394 v8::Handle<v8::Value> V8Converter::dateToV8(Dart_Handle value) |
| 395 { |
| 396 Dart_Handle exception = 0; |
| 397 v8::Handle<v8::Value> result = dateToV8(value, exception); |
| 398 ASSERT(!exception); |
| 399 return result; |
| 400 } |
| 401 |
| 402 v8::Handle<v8::Value> V8Converter::dateToV8(Dart_Handle value, Dart_Handle& exce
ption) |
| 403 { |
| 404 ASSERT(DartUtilities::isDateTime(DartDOMData::current(), value)); |
| 405 |
| 406 Dart_Handle asDouble = DartUtilities::invokeUtilsMethod("dateTimeToDouble",
1, &value); |
| 407 |
| 408 if (!DartUtilities::checkResult(asDouble, exception)) |
| 409 return v8::Handle<v8::Value>(); |
| 410 |
| 411 double doubleValue = DartUtilities::dartToDouble(asDouble, exception); |
| 412 |
| 413 return v8::Date::New(v8::Isolate::GetCurrent(), doubleValue); |
| 414 } |
| 415 |
| 416 Dart_Handle V8Converter::dateToDart(v8::Handle<v8::Value> value) |
| 417 { |
| 418 ASSERT(value->IsDate()); |
| 419 return DartUtilities::dateToDart(value->NumberValue()); |
| 420 } |
| 421 |
| 422 Dart_Handle V8Converter::listToDart(v8::Handle<v8::Array> value, V8ToDartMap& ma
p, Dart_Handle& exception) |
| 423 { |
| 424 ASSERT(value->IsArray()); |
| 425 |
| 426 uint32_t length = value->Length(); |
| 427 |
| 428 Dart_Handle list = Dart_NewList(length); |
| 429 ASSERT(!Dart_IsError(list)); |
| 430 map.put(value, list); |
| 431 |
| 432 for (uint32_t i = 0; i < length; ++i) { |
| 433 Dart_Handle result = toDart(value->Get(i), map, exception); |
| 434 if (exception) |
| 435 return 0; |
| 436 if (!DartUtilities::checkResult(result, exception)) |
| 437 return 0; |
| 438 result = Dart_ListSetAt(list, i, result); |
| 439 if (!DartUtilities::checkResult(result, exception)) |
| 440 return 0; |
| 441 } |
| 442 |
| 443 return list; |
| 444 } |
| 445 |
| 446 v8::Handle<v8::Value> V8Converter::mapToV8(Dart_Handle value, DartToV8Map& map,
Dart_Handle& exception) |
| 447 { |
| 448 Dart_Handle asList = DartUtilities::invokeUtilsMethod("convertMapToList", 1,
&value); |
| 449 if (!DartUtilities::checkResult(asList, exception)) |
| 450 return v8::Handle<v8::Value>(); |
| 451 ASSERT(Dart_IsList(asList)); |
| 452 |
| 453 // Now we have a list [key, value, key, value, ....], create a v8 object and
set necesary |
| 454 // properties on it. |
| 455 v8::Handle<v8::Object> object = v8::Object::New(v8::Isolate::GetCurrent()); |
| 456 map.put(value, object); |
| 457 |
| 458 // We converted to internal Dart list, methods shouldn't throw exceptions no
w. |
| 459 intptr_t length = 0; |
| 460 Dart_Handle ALLOW_UNUSED result = Dart_ListLength(asList, &length); |
| 461 ASSERT(!Dart_IsError(result)); |
| 462 ASSERT(!(length % 2)); |
| 463 for (intptr_t i = 0; i < length; i += 2) { |
| 464 v8::Handle<v8::Value> key = toV8(Dart_ListGetAt(asList, i), map, excepti
on); |
| 465 if (exception) |
| 466 return v8::Handle<v8::Value>(); |
| 467 v8::Handle<v8::Value> value = toV8(Dart_ListGetAt(asList, i + 1), map, e
xception); |
| 468 if (exception) |
| 469 return v8::Handle<v8::Value>(); |
| 470 |
| 471 object->Set(key, value); |
| 472 } |
| 473 |
| 474 return object; |
| 475 } |
| 476 |
| 477 Dart_Handle V8Converter::mapToDart(v8::Handle<v8::Object> object, V8ToDartMap& m
ap, Dart_Handle& exception) |
| 478 { |
| 479 v8::Handle<v8::Array> ownPropertyNames = object->GetOwnPropertyNames(); |
| 480 uint32_t ownPropertiesCount = ownPropertyNames->Length(); |
| 481 |
| 482 Dart_Handle result = DartUtilities::invokeUtilsMethod("createMap", 0, 0); |
| 483 ASSERT(!Dart_IsError(result)); |
| 484 map.put(object, result); |
| 485 |
| 486 Dart_Handle asList = Dart_NewList(ownPropertiesCount * 2); |
| 487 ASSERT(!Dart_IsError(asList)); |
| 488 |
| 489 for (uint32_t i = 0; i < ownPropertiesCount; i++) { |
| 490 v8::Handle<v8::Value> v8key = ownPropertyNames->Get(i); |
| 491 |
| 492 Dart_Handle key = toDart(v8key, map, exception); |
| 493 if (exception) |
| 494 return 0; |
| 495 Dart_ListSetAt(asList, 2 * i, key); |
| 496 |
| 497 Dart_Handle value = toDart(object->Get(v8key), map, exception); |
| 498 if (exception) |
| 499 return 0; |
| 500 Dart_ListSetAt(asList, 2 * i + 1, value); |
| 501 } |
| 502 |
| 503 Dart_Handle args[2] = { result, asList }; |
| 504 DartUtilities::invokeUtilsMethod("populateMap", 2, args); |
| 505 return result; |
| 506 } |
| 507 |
| 508 v8::Handle<v8::Value> V8Converter::arrayBufferToV8(Dart_Handle value, Dart_Handl
e& exception) |
| 509 { |
| 510 V8ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); |
| 511 return blink::toV8(DartUtilities::dartToExternalizedArrayBuffer(value, excep
tion).get(), state->context()->Global(), state->isolate()); |
| 512 } |
| 513 |
| 514 Dart_Handle V8Converter::arrayBufferToDart(v8::Handle<v8::Object> object, Dart_H
andle& exception) |
| 515 { |
| 516 return DartUtilities::arrayBufferToDart(V8ArrayBuffer::toImpl(object)); |
| 517 } |
| 518 |
| 519 v8::Handle<v8::Value> V8Converter::arrayBufferViewToV8(Dart_Handle value, Dart_H
andle& exception) |
| 520 { |
| 521 RefPtr<ArrayBufferView> view = DartUtilities::dartToExternalizedArrayBufferV
iew(value, exception); |
| 522 V8ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); |
| 523 |
| 524 switch (view->type()) { |
| 525 case ArrayBufferView::TypeInt8: |
| 526 return blink::toV8(static_cast<Int8Array*>(view.get()), state->context()
->Global(), state->isolate()); |
| 527 case ArrayBufferView::TypeUint8: |
| 528 return blink::toV8(static_cast<Uint8Array*>(view.get()), state->context(
)->Global(), state->isolate()); |
| 529 case ArrayBufferView::TypeUint8Clamped: |
| 530 return blink::toV8(static_cast<Uint8ClampedArray*>(view.get()), state->c
ontext()->Global(), state->isolate()); |
| 531 case ArrayBufferView::TypeInt16: |
| 532 return blink::toV8(static_cast<Int16Array*>(view.get()), state->context(
)->Global(), state->isolate()); |
| 533 case ArrayBufferView::TypeUint16: |
| 534 return blink::toV8(static_cast<Uint16Array*>(view.get()), state->context
()->Global(), state->isolate()); |
| 535 case ArrayBufferView::TypeInt32: |
| 536 return blink::toV8(static_cast<Int32Array*>(view.get()), state->context(
)->Global(), state->isolate()); |
| 537 case ArrayBufferView::TypeUint32: |
| 538 return blink::toV8(static_cast<Uint32Array*>(view.get()), state->context
()->Global(), state->isolate()); |
| 539 case ArrayBufferView::TypeFloat32: |
| 540 return blink::toV8(static_cast<Float32Array*>(view.get()), state->contex
t()->Global(), state->isolate()); |
| 541 case ArrayBufferView::TypeFloat64: |
| 542 return blink::toV8(static_cast<Float64Array*>(view.get()), state->contex
t()->Global(), state->isolate()); |
| 543 case ArrayBufferView::TypeDataView: |
| 544 return blink::toV8(static_cast<DataView*>(view.get()), state->context()-
>Global(), state->isolate()); |
| 545 default: |
| 546 ASSERT_NOT_REACHED(); |
| 547 return v8::Handle<v8::Value>(); |
| 548 } |
| 549 } |
| 550 |
| 551 Dart_Handle V8Converter::arrayBufferViewToDart(v8::Handle<v8::Object> object, Da
rt_Handle& exception) |
| 552 { |
| 553 RefPtr<ArrayBufferView> view = V8ArrayBufferView::toImpl(object); |
| 554 return DartUtilities::arrayBufferViewToDart(view.get()); |
| 555 } |
| 556 |
| 557 } // namespace blink |
OLD | NEW |