Skip to content

Commit 0299d71

Browse files
authored
Fixed unexpected lua error from Object.GetOwnPropertyDescriptors returning nil (#994)
1 parent e90fc31 commit 0299d71

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function __TS__ObjectGetOwnPropertyDescriptors(this: void, object: any): Record<any, PropertyDescriptor | undefined> {
22
const metatable = getmetatable(object);
33
if (!metatable) return {};
4-
return rawget(metatable, "_descriptors");
4+
return rawget(metatable, "_descriptors") || {};
55
}

test/unit/builtins/object.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,27 @@ describe("Object.getOwnPropertyDescriptors", () => {
211211
`.expectToMatchJsResult();
212212
});
213213
});
214+
215+
describe("delete from object", () => {
216+
test("delete from object", () => {
217+
util.testFunction`
218+
const obj = { foo: "bar", bar: "baz" };
219+
delete obj["foo"];
220+
return obj;
221+
`
222+
.setTsHeader("declare function setmetatable<T extends object>(this: void, table: T, metatable: any): T;")
223+
.expectToEqual({ bar: "baz" });
224+
});
225+
226+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/993
227+
test("delete from object with metatable", () => {
228+
util.testFunction`
229+
const obj = { foo: "bar", bar: "baz" };
230+
setmetatable(obj, {});
231+
delete obj["foo"];
232+
return obj;
233+
`
234+
.setTsHeader("declare function setmetatable<T extends object>(this: void, table: T, metatable: any): T;")
235+
.expectToEqual({ bar: "baz" });
236+
});
237+
});

0 commit comments

Comments
 (0)