Skip to content

Commit b64a14b

Browse files
committed
Testing own keys of object templates with empty enumerators.
1 parent 73290aa commit b64a14b

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

graal-nodejs/test/graal/unit/object_template.cc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
4545

4646
void SimpleAccessorGetter(Local<Name> property, const PropertyCallbackInfo<Value>& info);
4747
void SimpleAccessorSetter(Local<Name> property, Local<Value> value, const PropertyCallbackInfo<void>& info);
48+
void EmptyPropertyEnumeratorCallback(const PropertyCallbackInfo<Array>& info) {};
4849

4950
#endif
5051

@@ -128,4 +129,38 @@ EXPORT_TO_JS(CheckNamedHandlerWithInternalFields) {
128129
args.GetReturnValue().Set(expectedCount == actualCount);
129130
}
130131

132+
EXPORT_TO_JS(CreateWithEmptyIndexedEnumerator) {
133+
Isolate* isolate = args.GetIsolate();
134+
Local<ObjectTemplate> objectTemplate = ObjectTemplate::New(isolate);
135+
IndexedPropertyHandlerConfiguration handler(
136+
nullptr, // getter
137+
nullptr, // setter
138+
nullptr, // query
139+
nullptr, // deleter
140+
EmptyPropertyEnumeratorCallback // enumerator
141+
);
142+
objectTemplate->SetHandler(handler);
143+
144+
Local<Context> context = isolate->GetCurrentContext();
145+
Local<Object> instance = objectTemplate->NewInstance(context).ToLocalChecked();
146+
args.GetReturnValue().Set(instance);
147+
}
148+
149+
EXPORT_TO_JS(CreateWithEmptyNamedEnumerator) {
150+
Isolate* isolate = args.GetIsolate();
151+
Local<ObjectTemplate> objectTemplate = ObjectTemplate::New(isolate);
152+
NamedPropertyHandlerConfiguration handler(
153+
nullptr, // getter
154+
nullptr, // setter
155+
nullptr, // query
156+
nullptr, // deleter
157+
EmptyPropertyEnumeratorCallback // enumerator
158+
);
159+
objectTemplate->SetHandler(handler);
160+
161+
Local<Context> context = isolate->GetCurrentContext();
162+
Local<Object> instance = objectTemplate->NewInstance(context).ToLocalChecked();
163+
args.GetReturnValue().Set(instance);
164+
}
165+
131166
#undef SUITE

graal-nodejs/test/graal/unit/object_template.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -83,6 +83,14 @@ describe('ObjectTemplate', function () {
8383
it('should create object with the specified internal field count', function () {
8484
var result = module.ObjectTemplate_CheckNamedHandlerWithInternalFields();
8585
assert.ok(result);
86-
});
86+
});
87+
it('should not crash with an empty named enumerator', function () {
88+
var obj = module.ObjectTemplate_CreateWithEmptyNamedEnumerator();
89+
assert.strictEqual(Object.keys(obj).length, 0);
90+
});
91+
it('should not crash with an empty indexed enumerator', function () {
92+
var obj = module.ObjectTemplate_CreateWithEmptyIndexedEnumerator();
93+
assert.strictEqual(Object.keys(obj).length, 0);
94+
});
8795
});
8896
});

0 commit comments

Comments
 (0)