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

Unified Diff: Source/modules/gamepad/NavigatorGamepad.cpp

Issue 808643005: Sync Navigator.getGamepads() with the spec Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/NavigatorGamepad.cpp
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
index f0c840903e01c2528d944a8a25ac01bad9cbaab8..f56961b3f09808e6add91c535e72edc90399c8d3 100644
--- a/Source/modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp
@@ -94,9 +94,22 @@ WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
return NavigatorGamepad::from(navigator).webkitGamepads();
}
-GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator)
+HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(Navigator& navigator)
{
- return NavigatorGamepad::from(navigator).gamepads();
+ GamepadList* gamepadList = NavigatorGamepad::from(navigator).gamepads();
+ unsigned length = gamepadList->length();
+ HeapVector<Member<Gamepad>> gamepads(length);
+ unsigned actualLength = 0;
+ for (unsigned i = 0; i < length; ++i) {
+ Gamepad* gamepad = gamepadList->item(i);
+ if (gamepad) {
+ ASSERT(gamepad->index() == i);
+ gamepads[i] = gamepad;
kbalazs 2014/12/17 21:53:41 This should be gamepads[actualLength], no? It see
philipj_slow 2014/12/17 22:45:38 This started out as a loop simply copying gamepads
kbalazs 2014/12/18 00:34:39 I see this in Vector::shrink: TypeOperations::des
philipj_slow 2014/12/18 08:29:03 gamepad-polling-access.html tries exactly this, an
+ actualLength = i + 1;
+ }
+ }
+ gamepads.shrink(actualLength);
kbalazs 2014/12/17 21:53:41 In the common case this would allocate, deallocate
philipj_slow 2014/12/17 22:45:38 shrink() only modifies the size, it doesn't reallo
kbalazs 2014/12/18 00:34:39 Correct, it doesn't deallocate but it destroys ele
philipj_slow 2014/12/18 08:29:03 It's Member<Gamepad> being destroyed, so that seem
+ return gamepads;
}
WebKitGamepadList* NavigatorGamepad::webkitGamepads()
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698