Skip to content

Commit f10fa70

Browse files
committed
Fixing test to work around VS2013 object lifetime issue
1 parent 4a8728a commit f10fa70

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

test/object.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,26 @@ void DefineProperties(const CallbackInfo& info) {
3939
PropertyDescriptor::Function("function", TestFunction),
4040
});
4141
} else if (nameType.Utf8Value() == "string") {
42+
// VS2013 has lifetime issues when passing temporary objects into the constructor of another
43+
// object. It generates code to destruct the object as soon as the constructor call returns.
44+
// Since this isn't a common case for using std::string objects, I'm refactoring the test to
45+
// work around the issue.
46+
std::string str1("readonlyAccessor");
47+
std::string str2("readwriteAccessor");
48+
std::string str3("readonlyValue");
49+
std::string str4("readwriteValue");
50+
std::string str5("enumerableValue");
51+
std::string str6("configurableValue");
52+
std::string str7("function");
53+
4254
obj.DefineProperties({
43-
PropertyDescriptor::Accessor(std::string("readonlyAccessor"), TestGetter),
44-
PropertyDescriptor::Accessor(std::string("readwriteAccessor"), TestGetter, TestSetter),
45-
PropertyDescriptor::Value(std::string("readonlyValue"), trueValue),
46-
PropertyDescriptor::Value(std::string("readwriteValue"), trueValue, napi_writable),
47-
PropertyDescriptor::Value(std::string("enumerableValue"), trueValue, napi_enumerable),
48-
PropertyDescriptor::Value(std::string("configurableValue"), trueValue, napi_configurable),
49-
PropertyDescriptor::Function(std::string("function"), TestFunction),
55+
PropertyDescriptor::Accessor(str1, TestGetter),
56+
PropertyDescriptor::Accessor(str2, TestGetter, TestSetter),
57+
PropertyDescriptor::Value(str3, trueValue),
58+
PropertyDescriptor::Value(str4, trueValue, napi_writable),
59+
PropertyDescriptor::Value(str5, trueValue, napi_enumerable),
60+
PropertyDescriptor::Value(str6, trueValue, napi_configurable),
61+
PropertyDescriptor::Function(str7, TestFunction),
5062
});
5163
} else if (nameType.Utf8Value() == "value") {
5264
obj.DefineProperties({

0 commit comments

Comments
 (0)