diff --git a/ecmascript/builtins/builtins_collator.cpp b/ecmascript/builtins/builtins_collator.cpp index 2d30beb689362e11e99957512cfe94bf5f95af6b..b8869fe8e83bc94c08c1e5692dca64483ab5a321 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 8b83ae314ea6bcf7839a6c590970651f8b8d78bf..22cd4a17c76943839ab773d253f4cea45e396daa 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 8bd8bb70bf85471eb8d59e5117b9cac0da5abbc5..52c3b314885268b34ff250f043de92714c67430f 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 02c853165e8814fafc4f5aa95b184d379e652bda..54e1a3320066d27610813395335c999dbf017bc9 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 b9608aae523db04b4c6b7d8d5dd5b13b27a6e620..21d081acd14f53a2afd923f9af398b935c2cf107 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 51ff39ad6a97d45ab8bca6bff4832396a1ad7699..955870c7862f47f86b2efcd6c052b671af83c7ce 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 f2cdb6787145a3bcd21877f4b05cb2b21852e9c3..86764c7bf31109b431043fab113d9f81908483cb 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 ec048d172782c470b470d923eec0635103db2ce8..ad0c0e139372850e00a07e81b5505d20deffc864 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 58c97ca44d7f8addb5785e07a4cc69f15e2c022a..8632e4762ea6f96a239eb714a1f1b445c31e258b 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 bf0a2803e6a701411fc4f53708035541a52bb7a1..3f3fcda8c4e898b40d4001d7b282b7b816de8105 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 04a45eda5bc8bfaa965e74fb059b9880648a6ec4..c7023b7beaf417de2727f0bcad3eddf2508a0e86 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 3a867c91da0a2e810a18f9e418dc126ca05bb339..b4b69e168c43d3e4d2870fe34f4948e644e8fa1a 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 e0e4c0262919dc5e9a4caf639e502db2e39c6f83..454723e621eabd47e584177eff6616c7338265b0 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 42f1ecba5e8a0c6c2ed7cb2918ef4c97942ec0a0..52a1c1d8912f1b372561a5c9f41b505dde9a7b99 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 4c214186f5351457282535e4ffe1541e463d7cb8..351f49ec4e4ccd7ca24d1a2514c2174be01fe4a2 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 2b77f3603a6e3f7252af983fa320316e9ea1e382..64c2e0444a568dec8c584e65329ede5f17b432ff 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 22a1b50dcfef356b3f83fbf36742b79b0035eebd..879e46bedd0a3d6c1b8f82ea7362ac0c5124e1a5 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 b6cf3fb2154203ef13199c7190a7f7d92cbee00c..600936f9084614723d9fcc326497cdbaf369cd0d 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) +}