Skip to content

Commit

Permalink
Fix wrong behaviours in Promise.race() and Promise.All() functions
Browse files Browse the repository at this point in the history
The assertions were wrong, if the given `iterable` was not an `Object` or not an `ArrayObject` the promise should have been just rejected.
Fixes Samsung#25
Fixes Samsung#30

Signed-off-by: Daniel Balla [email protected]
  • Loading branch information
Daniel Balla committed Jan 21, 2019
1 parent 57b7532 commit 68a0619
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/runtime/GlobalObjectBuiltinPromise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ static Value builtinPromiseAll(ExecutionState& state, Value thisValue, size_t ar
remainingElementsCount->defineOwnProperty(state, strings->value, ObjectPropertyDescriptor(Value(1), ObjectPropertyDescriptor::AllPresent));
uint32_t index = 0;

ASSERT(iterable->isArrayObject()); // TODO
if (!iterable->isArrayObject()) {
return capability.m_rejectFunction;
}

ArrayObject* iterableArray = iterable->asArrayObject();

// 6. Repeat
Expand Down Expand Up @@ -205,7 +208,10 @@ static Value builtinPromiseRace(ExecutionState& state, Value thisValue, size_t a
ArrayObject* values = new ArrayObject(state);
uint32_t index = 0;

ASSERT(iterable->isArrayObject()); // TODO
if (!iterable->isArrayObject()) {
return capability.m_rejectFunction;
}

ArrayObject* iterableArray = iterable->asArrayObject();

// 6. Repeat
Expand Down
17 changes: 17 additions & 0 deletions test/regression-tests/issue-25.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Object.prototype[1] = 0;
Promise.race('multiline');
17 changes: 17 additions & 0 deletions test/regression-tests/issue-30.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Object.prototype[1] = 0;
Promise.all('x');

0 comments on commit 68a0619

Please sign in to comment.