mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-12-02 16:07:20 +00:00
fix mjsunit/es6/typedarray-iteration.js
Signed-off-by: liujia178 <liujia178@huawei.com>
This commit is contained in:
parent
6edecbeea4
commit
d50986f10d
@ -1383,4 +1383,69 @@ JSTaggedValue TypedArrayHelper::findLastIndexCommon(EcmaRuntimeCallInfo *argv,
|
||||
// 9. Return -1.
|
||||
return BuiltinsBase::GetTaggedDouble(-1);
|
||||
}
|
||||
|
||||
JSTaggedValue TypedArrayHelper::someCommon(EcmaRuntimeCallInfo *argv,
|
||||
JSHandle<JSTaggedValue> thisObjVal, int64_t len)
|
||||
{
|
||||
JSThread *thread = argv->GetThread();
|
||||
// 5. If IsCallable(callbackfn) is false, throw a TypeError exception.
|
||||
JSHandle<JSTaggedValue> callbackFnHandle = BuiltinsBase::GetCallArg(argv, 0);
|
||||
if (!callbackFnHandle->IsCallable()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception());
|
||||
}
|
||||
|
||||
// 6. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
JSHandle<JSTaggedValue> thisArgHandle = BuiltinsBase::GetCallArg(argv, 1);
|
||||
|
||||
// 7. Let k be 0.
|
||||
// 8. Repeat, while k < len
|
||||
// a. Let Pk be ToString(k).
|
||||
// b. Let kPresent be HasProperty(O, Pk).
|
||||
// c. ReturnIfAbrupt(kPresent).
|
||||
// d. If kPresent is true, then
|
||||
// i. Let kValue be Get(O, Pk).
|
||||
// ii. ReturnIfAbrupt(kValue).
|
||||
// iii. Let testResult be ToBoolean(Call(callbackfn, T, «kValue, k, and O»)).
|
||||
// iv. ReturnIfAbrupt(testResult).
|
||||
// v. If testResult is true, return true.
|
||||
// e. Increase k by 1.
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
uint32_t k = 0;
|
||||
JSTaggedValue callResult = BuiltinsBase::GetTaggedBoolean(false);
|
||||
if (thisObjVal->IsStableJSArray(thread)) {
|
||||
callResult = JSStableArray::HandleSomeOfStable(thread, JSHandle<JSObject>::Cast(thisObjVal),
|
||||
callbackFnHandle, thisArgHandle, k);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
return BuiltinsBase::GetTaggedBoolean(true);
|
||||
}
|
||||
}
|
||||
while (k < len) {
|
||||
bool exists = (BuiltinsBase::GetThis(argv)->IsTypedArray()
|
||||
|| BuiltinsBase::GetThis(argv)->IsSharedTypedArray()
|
||||
|| JSTaggedValue::HasProperty(thread, thisObjVal, k));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (exists) {
|
||||
key.Update(JSTaggedValue(k));
|
||||
JSHandle<JSTaggedValue> kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
const uint32_t argsLength = 3; // 3: «kValue, k, O»
|
||||
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue());
|
||||
callResult = JSFunction::Call(info);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
return BuiltinsBase::GetTaggedBoolean(true);
|
||||
}
|
||||
}
|
||||
k++;
|
||||
thread->CheckSafepointIfSuspended();
|
||||
}
|
||||
|
||||
// 9. Return false.
|
||||
return BuiltinsBase::GetTaggedBoolean(false);
|
||||
}
|
||||
} // namespace panda::ecmascript::base
|
||||
|
@ -102,6 +102,7 @@ public:
|
||||
static JSTaggedValue findLastCommon(EcmaRuntimeCallInfo *argv, JSHandle<JSTaggedValue> thisObjVal, int64_t len);
|
||||
static JSTaggedValue findLastIndexCommon(EcmaRuntimeCallInfo *argv,
|
||||
JSHandle<JSTaggedValue> thisObjVal, int64_t len);
|
||||
static JSTaggedValue someCommon(EcmaRuntimeCallInfo *argv, JSHandle<JSTaggedValue> thisObjVal, int64_t len);
|
||||
|
||||
#define DEFINE_GET_ONHEAP_HCLASS_FROM_TYPE(Type) \
|
||||
inline static JSHandle<JSHClass> GetOnHeapHclass##Type(JSThread *thread, JSHClass* objHclass);
|
||||
|
@ -2137,67 +2137,10 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv)
|
||||
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
|
||||
|
||||
// 3. Let len be ToLength(Get(O, "length")).
|
||||
int64_t len = ArrayHelper::GetLength(thread, thisObjVal);
|
||||
int64_t len = ArrayHelper::GetArrayLength(thread, thisObjVal);
|
||||
// 4. ReturnIfAbrupt(len).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// 5. If IsCallable(callbackfn) is false, throw a TypeError exception.
|
||||
JSHandle<JSTaggedValue> callbackFnHandle = GetCallArg(argv, 0);
|
||||
if (!callbackFnHandle->IsCallable()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception());
|
||||
}
|
||||
|
||||
// 6. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
JSHandle<JSTaggedValue> thisArgHandle = GetCallArg(argv, 1);
|
||||
|
||||
// 7. Let k be 0.
|
||||
// 8. Repeat, while k < len
|
||||
// a. Let Pk be ToString(k).
|
||||
// b. Let kPresent be HasProperty(O, Pk).
|
||||
// c. ReturnIfAbrupt(kPresent).
|
||||
// d. If kPresent is true, then
|
||||
// i. Let kValue be Get(O, Pk).
|
||||
// ii. ReturnIfAbrupt(kValue).
|
||||
// iii. Let testResult be ToBoolean(Call(callbackfn, T, «kValue, k, and O»)).
|
||||
// iv. ReturnIfAbrupt(testResult).
|
||||
// v. If testResult is true, return true.
|
||||
// e. Increase k by 1.
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
uint32_t k = 0;
|
||||
JSTaggedValue callResult = GetTaggedBoolean(false);
|
||||
if (thisObjVal->IsStableJSArray(thread)) {
|
||||
callResult = JSStableArray::HandleSomeOfStable(thread, thisObjHandle, callbackFnHandle, thisArgHandle, k);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
return GetTaggedBoolean(true);
|
||||
}
|
||||
}
|
||||
while (k < len) {
|
||||
bool exists = (thisHandle->IsTypedArray() || thisHandle->IsSharedTypedArray() ||
|
||||
JSTaggedValue::HasProperty(thread, thisObjVal, k));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (exists) {
|
||||
key.Update(JSTaggedValue(k));
|
||||
JSHandle<JSTaggedValue> kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
const uint32_t argsLength = 3; // 3: «kValue, k, O»
|
||||
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
|
||||
EcmaRuntimeCallInfo *info =
|
||||
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue());
|
||||
callResult = JSFunction::Call(info);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
if (callResult.ToBoolean()) {
|
||||
return GetTaggedBoolean(true);
|
||||
}
|
||||
}
|
||||
k++;
|
||||
thread->CheckSafepointIfSuspended();
|
||||
}
|
||||
|
||||
// 9. Return false.
|
||||
return GetTaggedBoolean(false);
|
||||
return TypedArrayHelper::someCommon(argv, thisObjVal, len);
|
||||
}
|
||||
|
||||
// 22.1.3.24 Array.prototype.sort (comparefn)
|
||||
|
@ -1474,11 +1474,21 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv)
|
||||
JSTaggedValue BuiltinsTypedArray::Some(EcmaRuntimeCallInfo *argv)
|
||||
{
|
||||
ASSERT(argv);
|
||||
BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Some);
|
||||
if (!GetThis(argv)->IsTypedArray()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception());
|
||||
}
|
||||
return BuiltinsArray::Some(argv);
|
||||
JSThread *thread = argv->GetThread();
|
||||
BUILTINS_API_TRACE(thread, TypedArray, Some);
|
||||
JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
|
||||
// 2. Let valid be ValidateTypedArray(O).
|
||||
TypedArrayHelper::ValidateTypedArray(thread, thisHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// 1. Let O be ToObject(this value).
|
||||
JSHandle<JSObject> thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
JSHandle<JSTaggedValue> thisObjVal(thisObjHandle);
|
||||
|
||||
// 3. Let len be ToLength(Get(O, "length")).
|
||||
int64_t len = JSHandle<JSTypedArray>::Cast(thisObjVal)->GetArrayLength();
|
||||
return TypedArrayHelper::someCommon(argv, thisObjVal, len);
|
||||
}
|
||||
|
||||
// 22.2.3.25
|
||||
|
@ -1293,12 +1293,16 @@ void BuiltinsTypedArrayStubBuilder::Some(GateRef glue, GateRef thisValue, GateRe
|
||||
Label ecmaObj(env);
|
||||
Label typedArray(env);
|
||||
Label thisExists(env);
|
||||
Label notDetached(env);
|
||||
BRANCH(IsEcmaObject(thisValue), &ecmaObj, slowPath);
|
||||
Bind(&ecmaObj);
|
||||
BRANCH(IsTypedArray(thisValue), &typedArray, slowPath);
|
||||
Bind(&typedArray);
|
||||
BRANCH(TaggedIsUndefinedOrNull(thisValue), slowPath, &thisExists);
|
||||
Bind(&thisExists);
|
||||
GateRef buffer = GetViewedArrayBuffer(thisValue);
|
||||
BRANCH(IsDetachedBuffer(buffer), slowPath, ¬Detached);
|
||||
Bind(¬Detached);
|
||||
|
||||
Label arg0HeapObject(env);
|
||||
Label callable(env);
|
||||
@ -1376,6 +1380,7 @@ void BuiltinsTypedArrayStubBuilder::Filter(GateRef glue, GateRef thisValue, Gate
|
||||
{
|
||||
auto env = GetEnvironment();
|
||||
Label thisExists(env);
|
||||
Label notDetached(env);
|
||||
Label isEcmaObject(env);
|
||||
Label isFastTypedArray(env);
|
||||
Label defaultConstr(env);
|
||||
@ -1384,6 +1389,9 @@ void BuiltinsTypedArrayStubBuilder::Filter(GateRef glue, GateRef thisValue, Gate
|
||||
Label accessorNotChanged(env);
|
||||
BRANCH(TaggedIsUndefinedOrNull(thisValue), slowPath, &thisExists);
|
||||
Bind(&thisExists);
|
||||
GateRef buffer = GetViewedArrayBuffer(thisValue);
|
||||
BRANCH(IsDetachedBuffer(buffer), slowPath, ¬Detached);
|
||||
Bind(¬Detached);
|
||||
BRANCH(IsEcmaObject(thisValue), &isEcmaObject, slowPath);
|
||||
Bind(&isEcmaObject);
|
||||
GateRef arrayType = GetObjectType(LoadHClass(thisValue));
|
||||
@ -2583,6 +2591,7 @@ void BuiltinsTypedArrayStubBuilder::Map(GateRef glue, GateRef thisValue, GateRef
|
||||
Label prototypeIsEcmaObj(env);
|
||||
Label isProtoChangeMarker(env);
|
||||
Label accessorNotChanged(env);
|
||||
Label notDetached(env);
|
||||
BRANCH(TaggedIsUndefinedOrNull(thisValue), slowPath, &thisExists);
|
||||
Bind(&thisExists);
|
||||
BRANCH(TaggedIsHeapObject(thisValue), &isHeapObject, slowPath);
|
||||
@ -2591,6 +2600,9 @@ void BuiltinsTypedArrayStubBuilder::Map(GateRef glue, GateRef thisValue, GateRef
|
||||
Bind(&typedArrayIsFast);
|
||||
BRANCH(HasConstructor(thisValue), slowPath, &defaultConstr);
|
||||
Bind(&defaultConstr);
|
||||
GateRef buffer = GetViewedArrayBuffer(thisValue);
|
||||
BRANCH(IsDetachedBuffer(buffer), slowPath, ¬Detached);
|
||||
Bind(¬Detached);
|
||||
GateRef prototype = GetPrototypeFromHClass(LoadHClass(thisValue));
|
||||
BRANCH(IsEcmaObject(prototype), &prototypeIsEcmaObj, slowPath);
|
||||
Bind(&prototypeIsEcmaObj);
|
||||
|
@ -249,4 +249,9 @@ Test New Uint8ClampedArray with Bad_Obj Success!
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
false
|
@ -1006,3 +1006,34 @@ try {
|
||||
} catch(e) {
|
||||
print(e instanceof TypeError);
|
||||
}
|
||||
|
||||
var arr_map = new Uint8Array([11, 22, 33, 44]);
|
||||
ArkTools.arrayBufferDetach(arr_map.buffer);
|
||||
try {
|
||||
arr_map.map((v) => v)
|
||||
} catch (e) {
|
||||
print(e instanceof TypeError)
|
||||
}
|
||||
|
||||
var arr_filter = new Uint8Array([11, 22]);
|
||||
ArkTools.arrayBufferDetach(arr_filter.buffer);
|
||||
try {
|
||||
arr_filter.filter(false)
|
||||
} catch (e) {
|
||||
print(e instanceof TypeError)
|
||||
}
|
||||
|
||||
var arr_some = new Uint8Array([11, 22]);
|
||||
ArkTools.arrayBufferDetach(arr_some.buffer);
|
||||
try {
|
||||
arr_some.some(false)
|
||||
} catch (e) {
|
||||
print(e instanceof TypeError)
|
||||
}
|
||||
|
||||
var arr_some1 = new Uint8Array([33, 44]);
|
||||
Object.defineProperty(arr_some1, 'length', { value: 1 });
|
||||
print(arr_some1.some(function(elt) { return elt == 44; }));
|
||||
print(Array.prototype.some.call(arr_some1, function(elt) {
|
||||
return elt == 44;
|
||||
}));
|
||||
|
@ -2969,7 +2969,6 @@
|
||||
"mjsunit/es6/proxies-cross-realm-exception.js",
|
||||
"mjsunit/es6/super-with-spread-modify-next.js",
|
||||
"mjsunit/es6/array-of.js",
|
||||
"mjsunit/es6/typedarray-iteration.js",
|
||||
"mjsunit/es6/array-iterator-detached.js",
|
||||
"mjsunit/es6/block-let-semantics-sloppy.js",
|
||||
"mjsunit/es6/string-iterator6.js",
|
||||
|
Loading…
Reference in New Issue
Block a user