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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/NativeValueTraitsImpl.h

Issue 2900743002: bindings: Do not skip symbols in the JS -> record<> conversion. (Closed)
Patch Set: Fix tests Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NativeValueTraitsImpl_h 5 #ifndef NativeValueTraitsImpl_h
6 #define NativeValueTraitsImpl_h 6 #define NativeValueTraitsImpl_h
7 7
8 #include "bindings/core/v8/IDLTypes.h" 8 #include "bindings/core/v8/IDLTypes.h"
9 #include "bindings/core/v8/NativeValueTraits.h" 9 #include "bindings/core/v8/NativeValueTraits.h"
10 #include "bindings/core/v8/V8BindingForCore.h" 10 #include "bindings/core/v8/V8BindingForCore.h"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return ImplType(); 423 return ImplType();
424 } 424 }
425 v8::Local<v8::Object> v8_object = v8::Local<v8::Object>::Cast(v8_value); 425 v8::Local<v8::Object> v8_object = v8::Local<v8::Object>::Cast(v8_value);
426 v8::TryCatch block(isolate); 426 v8::TryCatch block(isolate);
427 427
428 // "3. Let keys be ? O.[[OwnPropertyKeys]]()." 428 // "3. Let keys be ? O.[[OwnPropertyKeys]]()."
429 v8::Local<v8::Array> keys; 429 v8::Local<v8::Array> keys;
430 // While we could pass v8::ONLY_ENUMERABLE below, doing so breaks 430 // While we could pass v8::ONLY_ENUMERABLE below, doing so breaks
431 // web-platform-tests' headers-record.html and deviates from the spec 431 // web-platform-tests' headers-record.html and deviates from the spec
432 // algorithm. 432 // algorithm.
433 // Symbols are being skipped due to
434 // https://github.com/heycam/webidl/issues/294.
435 if (!v8_object 433 if (!v8_object
436 ->GetOwnPropertyNames(context, 434 ->GetOwnPropertyNames(context,
437 static_cast<v8::PropertyFilter>( 435 static_cast<v8::PropertyFilter>(
438 v8::PropertyFilter::ALL_PROPERTIES | 436 v8::PropertyFilter::ALL_PROPERTIES))
439 v8::PropertyFilter::SKIP_SYMBOLS))
440 .ToLocal(&keys)) { 437 .ToLocal(&keys)) {
441 exception_state.RethrowV8Exception(block.Exception()); 438 exception_state.RethrowV8Exception(block.Exception());
442 return ImplType(); 439 return ImplType();
443 } 440 }
444 if (keys->Length() > ImplType::MaxCapacity()) { 441 if (keys->Length() > ImplType::MaxCapacity()) {
445 exception_state.ThrowRangeError("Array length exceeds supported limit."); 442 exception_state.ThrowRangeError("Array length exceeds supported limit.");
446 return ImplType(); 443 return ImplType();
447 } 444 }
448 445
449 // "2. Let result be a new empty instance of record<K, V>." 446 // "2. Let result be a new empty instance of record<K, V>."
450 ImplType result; 447 ImplType result;
451 result.ReserveInitialCapacity(keys->Length()); 448 result.ReserveInitialCapacity(keys->Length());
452 449
453 // The conversion algorithm needs a data structure with fast insertion at 450 // The conversion algorithm needs a data structure with fast insertion at
454 // the end while at the same time requiring fast checks for previous insert 451 // the end while at the same time requiring fast checks for previous insert
455 // of a given key. |seenKeys| is a key/position in |result| map that aids in 452 // of a given key. |seenKeys| is a key/position in |result| map that aids in
456 // the latter part. 453 // the latter part.
457 HashMap<String, size_t> seen_keys; 454 HashMap<String, size_t> seen_keys;
458 455
459 for (uint32_t i = 0; i < keys->Length(); ++i) { 456 for (uint32_t i = 0; i < keys->Length(); ++i) {
460 // "4. Repeat, for each element key of keys in List order:" 457 // "4. Repeat, for each element key of keys in List order:"
461 v8::Local<v8::Value> key; 458 v8::Local<v8::Value> key;
462 if (!keys->Get(context, i).ToLocal(&key)) { 459 if (!keys->Get(context, i).ToLocal(&key)) {
463 exception_state.RethrowV8Exception(block.Exception()); 460 exception_state.RethrowV8Exception(block.Exception());
464 return ImplType(); 461 return ImplType();
465 } 462 }
466 463
464 // V8's GetOwnPropertyNames() does not convert numeric property indices
465 // to strings, so we have to do it ourselves.
466 if (!key->IsName())
467 key = key->ToString(context).ToLocalChecked();
468
467 // "4.1. Let desc be ? O.[[GetOwnProperty]](key)." 469 // "4.1. Let desc be ? O.[[GetOwnProperty]](key)."
468 v8::Local<v8::Value> desc; 470 v8::Local<v8::Value> desc;
469 if (!v8_object 471 if (!v8_object->GetOwnPropertyDescriptor(context, key.As<v8::Name>())
470 ->GetOwnPropertyDescriptor(
471 context, key->ToString(context).ToLocalChecked())
472 .ToLocal(&desc)) { 472 .ToLocal(&desc)) {
473 exception_state.RethrowV8Exception(block.Exception()); 473 exception_state.RethrowV8Exception(block.Exception());
474 return ImplType(); 474 return ImplType();
475 } 475 }
476 476
477 // "4.2. If desc is not undefined and desc.[[Enumerable]] is true:" 477 // "4.2. If desc is not undefined and desc.[[Enumerable]] is true:"
478 // We can call ToLocalChecked() and ToChecked() here because 478 // We can call ToLocalChecked() and ToChecked() here because
479 // GetOwnPropertyDescriptor is responsible for catching any exceptions 479 // GetOwnPropertyDescriptor is responsible for catching any exceptions
480 // and failures, and if we got to this point of the code we have a proper 480 // and failures, and if we got to this point of the code we have a proper
481 // object that was not created by a user. 481 // object that was not created by a user.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 524 }
525 } 525 }
526 // "5. Return result." 526 // "5. Return result."
527 return result; 527 return result;
528 } 528 }
529 }; 529 };
530 530
531 } // namespace blink 531 } // namespace blink
532 532
533 #endif // NativeValueTraitsImpl_h 533 #endif // NativeValueTraitsImpl_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698