From 120ecabe529e2462e5fae95478e594f370ed3530 Mon Sep 17 00:00:00 2001 From: hwx1163501 Date: Tue, 19 Mar 2024 09:24:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=91=E5=8D=956259=206287=E5=88=B04.0releas?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hwx1163501 issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I98NB3 --- ecmascript/builtins/builtins_collator.cpp | 4 +- ecmascript/builtins/builtins_date.cpp | 4 +- .../builtins/builtins_date_time_format.cpp | 4 +- ecmascript/builtins/builtins_displaynames.cpp | 4 +- ecmascript/builtins/builtins_list_format.cpp | 4 +- ecmascript/builtins/builtins_locale.cpp | 4 +- .../builtins/builtins_number_format.cpp | 4 +- ecmascript/builtins/builtins_plural_rules.cpp | 4 +- ecmascript/builtins/builtins_promise.cpp | 4 +- .../builtins_relative_time_format.cpp | 4 +- ecmascript/js_hclass.cpp | 3 ++ ecmascript/js_primitive_ref.cpp | 1 + ecmascript/object_factory.cpp | 4 +- ecmascript/stubs/runtime_stubs-inl.h | 1 + test/moduletest/array/array.js | 30 ++++++++++++++ test/moduletest/array/expect_output.txt | 1 + test/moduletest/fortest/expect_output.txt | 13 ++++++ test/moduletest/fortest/fortest.js | 40 +++++++++++++++++-- 18 files changed, 109 insertions(+), 24 deletions(-) diff --git a/ecmascript/builtins/builtins_collator.cpp b/ecmascript/builtins/builtins_collator.cpp index 2d30beb689..b8869fe8e8 100644 --- a/ecmascript/builtins/builtins_collator.cpp +++ b/ecmascript/builtins/builtins_collator.cpp @@ -48,9 +48,9 @@ JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) // a. Append [[CaseFirst]] as the last element of internalSlotsList. // 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%CollatorPrototype%", internalSlotsList). - JSHandle collator = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle collator = JSHandle::Cast(newObject); // 6. Return ? InitializeCollator(collator, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_date.cpp b/ecmascript/builtins/builtins_date.cpp index 8b83ae314e..22cd4a17c7 100644 --- a/ecmascript/builtins/builtins_date.cpp +++ b/ecmascript/builtins/builtins_date.cpp @@ -95,9 +95,9 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle constructor(GetConstructor(argv)); - JSHandle dateObject = - JSHandle::Cast(factory->NewJSObjectByConstructor(constructor, newTarget)); + JSHandle obj = factory->NewJSObjectByConstructor(constructor, newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle dateObject = JSHandle::Cast(obj); dateObject->SetTimeValue(thread, timeValue); return dateObject.GetTaggedValue(); } diff --git a/ecmascript/builtins/builtins_date_time_format.cpp b/ecmascript/builtins/builtins_date_time_format.cpp index 8bd8bb70bf..52c3b31488 100644 --- a/ecmascript/builtins/builtins_date_time_format.cpp +++ b/ecmascript/builtins/builtins_date_time_format.cpp @@ -45,9 +45,9 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI // [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], // [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], // [[Pattern]], [[BoundFormat]] »). - JSHandle dateTimeFormat = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle dateTimeFormat = JSHandle::Cast(newObject); // 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_displaynames.cpp b/ecmascript/builtins/builtins_displaynames.cpp index 02c853165e..54e1a33200 100644 --- a/ecmascript/builtins/builtins_displaynames.cpp +++ b/ecmascript/builtins/builtins_displaynames.cpp @@ -43,9 +43,9 @@ JSTaggedValue BuiltinsDisplayNames::DisplayNamesConstructor(EcmaRuntimeCallInfo // 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", // « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). JSHandle constructor = GetConstructor(argv); - JSHandle displayNames = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle displayNames = JSHandle::Cast(newObject); // 3. Perform ? InitializeDisplayNames(displayNames, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_list_format.cpp b/ecmascript/builtins/builtins_list_format.cpp index b9608aae52..21d081acd1 100644 --- a/ecmascript/builtins/builtins_list_format.cpp +++ b/ecmascript/builtins/builtins_list_format.cpp @@ -44,9 +44,9 @@ JSTaggedValue BuiltinsListFormat::ListFormatConstructor(EcmaRuntimeCallInfo *arg // [[Type]], [[Style]], [[Templates]] »). JSHandle constructor = GetConstructor(argv); - JSHandle listFormat = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle listFormat = JSHandle::Cast(newObject); // 3. Perform ? InitializeListFormat(listFormat, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_locale.cpp b/ecmascript/builtins/builtins_locale.cpp index 51ff39ad6a..955870c786 100644 --- a/ecmascript/builtins/builtins_locale.cpp +++ b/ecmascript/builtins/builtins_locale.cpp @@ -39,9 +39,9 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList). JSHandle constructor = GetConstructor(argv); - JSHandle locale = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle locale =JSHandle::Cast(newObject); // 7. If Type(tag) is not String or Object, throw a TypeError exception. JSHandle tag = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_number_format.cpp b/ecmascript/builtins/builtins_number_format.cpp index f2cdb67871..86764c7bf3 100644 --- a/ecmascript/builtins/builtins_number_format.cpp +++ b/ecmascript/builtins/builtins_number_format.cpp @@ -48,9 +48,9 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo // [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], // [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], // [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »). - JSHandle numberFormat = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle numberFormat = JSHandle::Cast(newObject); // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_plural_rules.cpp b/ecmascript/builtins/builtins_plural_rules.cpp index ec048d1727..ad0c0e1393 100644 --- a/ecmascript/builtins/builtins_plural_rules.cpp +++ b/ecmascript/builtins/builtins_plural_rules.cpp @@ -41,9 +41,9 @@ JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *a // 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRulesPrototype%", // « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], // [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »). - JSHandle pluralRules = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle pluralRules = JSHandle::Cast(newObject); // 3. Return ? InitializePluralRules(pluralRules, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_promise.cpp b/ecmascript/builtins/builtins_promise.cpp index 58c97ca44d..8632e4762e 100644 --- a/ecmascript/builtins/builtins_promise.cpp +++ b/ecmascript/builtins/builtins_promise.cpp @@ -60,9 +60,9 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor(EcmaRuntimeCallInfo *argv) // «[[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]]» ). // 4. ReturnIfAbrupt(promise). JSHandle constructor = GetConstructor(argv); - JSHandle instancePromise = - JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle instancePromise = JSHandle::Cast(newObject); // 5. Set promise's [[PromiseState]] internal slot to "pending". // 6. Set promise's [[PromiseFulfillReactions]] internal slot to a new empty List. diff --git a/ecmascript/builtins/builtins_relative_time_format.cpp b/ecmascript/builtins/builtins_relative_time_format.cpp index bf0a2803e6..3f3fcda8c4 100644 --- a/ecmascript/builtins/builtins_relative_time_format.cpp +++ b/ecmascript/builtins/builtins_relative_time_format.cpp @@ -37,9 +37,9 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt // (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]], // [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). JSHandle constructor = GetConstructor(argv); - JSHandle relativeTimeFormat = JSHandle::Cast( - factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget)); + JSHandle newObject = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle relativeTimeFormat = JSHandle::Cast(newObject); // 3. Perform ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). JSHandle locales = GetCallArg(argv, 0); diff --git a/ecmascript/js_hclass.cpp b/ecmascript/js_hclass.cpp index 04a45eda5b..c7023b7bea 100644 --- a/ecmascript/js_hclass.cpp +++ b/ecmascript/js_hclass.cpp @@ -619,6 +619,9 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandleGetPrototype(); ASSERT(proto.IsECMAObject()); JSTaggedValue protoDetailsValue = JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->GetProtoChangeDetails(); + if (protoDetailsValue.IsUndefined() || protoDetailsValue.IsNull()) { + return false; + } ASSERT(protoDetailsValue.IsProtoChangeDetails()); JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); ASSERT(!listenersValue.IsUndefined()); diff --git a/ecmascript/js_primitive_ref.cpp b/ecmascript/js_primitive_ref.cpp index 3a867c91da..b4b69e168c 100644 --- a/ecmascript/js_primitive_ref.cpp +++ b/ecmascript/js_primitive_ref.cpp @@ -35,6 +35,7 @@ JSHandle JSPrimitiveRef::StringCreate(JSThread *thread, const JS // 6. Set S.[[OwnPropertyKeys]] as specified. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle str(factory->NewJSString(value, newTarget)); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPrimitiveRef, thread); // 7. Let length be the number of code unit elements in value. JSHandle lengthStr = thread->GlobalConstants()->GetHandledLengthString(); uint32_t length = EcmaStringAccessor(value->GetTaggedObject()).GetLength(); diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index e0e4c02629..454723e621 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -1860,7 +1860,9 @@ JSHandle ObjectFactory::NewJSString(const JSHandleIsUndefined()) { obj = JSHandle::Cast(NewJSObjectByConstructor(stringFunc)); } else { - obj = JSHandle::Cast(NewJSObjectByConstructor(stringFunc, newTarget)); + JSHandle newObject = NewJSObjectByConstructor(stringFunc, newTarget); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPrimitiveRef, thread_); + obj = JSHandle::Cast(newObject); } obj->SetValue(thread_, str); return obj; diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 42f1ecba5e..52a1c1d891 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -2443,6 +2443,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructGeneric(JSThread *thread, JSHandl if (ctor->IsBase()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); obj = JSHandle(factory->NewJSObjectByConstructor(ctor, newTgt)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); diff --git a/test/moduletest/array/array.js b/test/moduletest/array/array.js index 4c214186f5..351f49ec4e 100644 --- a/test/moduletest/array/array.js +++ b/test/moduletest/array/array.js @@ -159,3 +159,33 @@ const values = [1, 10, 21, 2]; const sortedValues = values.toSorted((a, b) => {return a- b}); print(sortedValues); // [1, 2, 10, 21] print(values); // [1, 10, 21, 2] + +function fun1(obj, name, type) { + return typeof type === 'undefined' || typeof desc.value === type; + } + function fun2(obj, type) { + let properties = []; + let proto = Object.getPrototypeOf(obj); + while (proto && proto != Object.prototype) { + Object.getOwnPropertyNames(proto).forEach(name => { + if (name !== 'constructor') { + if (fun1(proto, name, type)) properties.push(name); + } + }); + proto = Object.getPrototypeOf(proto); + } + return properties; + } + function fun4(seed) { + let objects = [Object, Error, AggregateError, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, String, BigInt, Function, Number, Boolean, Date, RegExp, Array, ArrayBuffer, DataView, Int8Array, Int16Array, Int32Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array, Set, Map, WeakMap, WeakSet, Symbol, Proxy]; + return objects[seed % objects.length]; + } + function fun8(obj, seed) { + let properties = fun2(obj); + } + + fun4(694532)[fun8(fun4(694532), 527224)]; + Object.freeze(Object.prototype); + + Array.prototype.length = 3000; + print(Array.prototype.length) diff --git a/test/moduletest/array/expect_output.txt b/test/moduletest/array/expect_output.txt index 2b77f3603a..64c2e0444a 100644 --- a/test/moduletest/array/expect_output.txt +++ b/test/moduletest/array/expect_output.txt @@ -83,3 +83,4 @@ Dec,Feb,Jan,Mar Mar,Jan,Feb,Dec 1,2,10,21 1,10,21,2 +3000 diff --git a/test/moduletest/fortest/expect_output.txt b/test/moduletest/fortest/expect_output.txt index 22a1b50dcf..879e46bedd 100644 --- a/test/moduletest/fortest/expect_output.txt +++ b/test/moduletest/fortest/expect_output.txt @@ -63,3 +63,16 @@ p28 28 p29 29 p30 30 p31 31 +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK +Error: OK diff --git a/test/moduletest/fortest/fortest.js b/test/moduletest/fortest/fortest.js index b6cf3fb215..600936f908 100644 --- a/test/moduletest/fortest/fortest.js +++ b/test/moduletest/fortest/fortest.js @@ -22,15 +22,14 @@ let a = '*' let s = '' -for (let i = 0; i < 10; i++) -{ +for (let i = 0; i < 10; i++) { s += a print(s) } let i = 10 -while (i > 0) { +while (i > 0) { print(i); i--; } @@ -49,3 +48,38 @@ for (let index = 0; index < 32; index++) { for (let k in v5) { print(k, v5[k]); } + +function f0(v1, v2) { + try { + v1(); + } catch (v5) { + print(v5) + } +} + +try { + var v0 = function () { }.bind(); +} catch (e) { + print(e) +} + +try { + Object.defineProperty(v0, "prototype", { + get() { + throw Error("OK"); + } + }); +} catch (e) { + print(e) +} + +try { +[Array, Date, Boolean, Number, String, RegExp, Error, Uint8Array, ArrayBuffer, Map, WeakMap, Set, WeakSet]. + forEach(function (v6) { + f0(() => { + Reflect.construct(v6, [], v0); + }, `Error: OK`); + }); +} catch (e) { + print(e) +} -- Gitee