Skip to content

Commit c97fb6e

Browse files
author
Ian Halliday
committed
Add %AsyncFunction% API tests and fix bugs
Moved async function tests to a new test folder, es7. Added asyncawait-apis.js test file to cover the API structure defined by the spec for %AsyncFunction% and %AsyncFunctionPrototype%. Added functionality test for %AsyncFunction% constructor behavior. Noticed generator constructor didn't have test for name property; added. Fixed broken toString of async functions -- they were missing the async keyword. Fixed async functions incorrectly having caller and arguments properties.
1 parent 77cb9e4 commit c97fb6e

12 files changed

Lines changed: 904 additions & 657 deletions

lib/Runtime/Library/JavascriptFunction.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,15 @@ namespace Js
21202120

21212121
bool JavascriptFunction::HasRestrictedProperties() const
21222122
{
2123-
return !(this->functionInfo->IsClassMethod() || this->functionInfo->IsClassConstructor() || this->functionInfo->IsLambda() || this->IsGeneratorFunction() || this->IsBoundFunction() || this->IsStrictMode());
2123+
return !(
2124+
this->functionInfo->IsClassMethod() ||
2125+
this->functionInfo->IsClassConstructor() ||
2126+
this->functionInfo->IsLambda() ||
2127+
this->functionInfo->IsAsync() ||
2128+
this->IsGeneratorFunction() ||
2129+
this->IsBoundFunction() ||
2130+
this->IsStrictMode()
2131+
);
21242132
}
21252133

21262134
BOOL JavascriptFunction::HasProperty(PropertyId propertyId)

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ namespace Js
11531153
stringTypeDisplayString = CreateStringFromCppLiteral(L"string");
11541154
functionPrefixString = CreateStringFromCppLiteral(L"function ");
11551155
generatorFunctionPrefixString = CreateStringFromCppLiteral(L"function* ");
1156+
asyncFunctionPrefixString = CreateStringFromCppLiteral(L"async function ");
11561157
functionDisplayString = CreateStringFromCppLiteral(JS_DISPLAY_STRING_FUNCTION_ANONYMOUS);
11571158
xDomainFunctionDisplayString = CreateStringFromCppLiteral(L"\012function anonymous() {\012 [x-domain code]\012}\012");
11581159
invalidDateString = CreateStringFromCppLiteral(L"Invalid Date");

lib/Runtime/Library/JavascriptLibrary.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ namespace Js
285285
JavascriptString* errorDisplayString;
286286
JavascriptString* functionPrefixString;
287287
JavascriptString* generatorFunctionPrefixString;
288+
JavascriptString* asyncFunctionPrefixString;
288289
JavascriptString* functionDisplayString;
289290
JavascriptString* xDomainFunctionDisplayString;
290291
JavascriptString* undefinedDisplayString;
@@ -499,6 +500,7 @@ namespace Js
499500
JavascriptString* GetErrorDisplayString() const { return errorDisplayString; }
500501
JavascriptString* GetFunctionPrefixString() { return functionPrefixString; }
501502
JavascriptString* GetGeneratorFunctionPrefixString() { return generatorFunctionPrefixString; }
503+
JavascriptString* GetAsyncFunctionPrefixString() { return asyncFunctionPrefixString; }
502504
JavascriptString* GetFunctionDisplayString() { return functionDisplayString; }
503505
JavascriptString* GetXDomainFunctionDisplayString() { return xDomainFunctionDisplayString; }
504506
JavascriptString* GetInvalidDateString() { return invalidDateString; }

lib/Runtime/Library/ScriptFunction.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ namespace Js
350350
return inputString;
351351
}
352352

353-
ScriptContext * scriptContext = this->GetScriptContext();
354-
JavascriptLibrary *javascriptLibrary = scriptContext->GetLibrary();
353+
ScriptContext* scriptContext = this->GetScriptContext();
354+
JavascriptLibrary* library = scriptContext->GetLibrary();
355355
bool isClassMethod = this->GetFunctionInfo()->IsClassMethod() || this->GetFunctionInfo()->IsClassConstructor();
356356

357357
JavascriptString* prefixString = nullptr;
@@ -362,10 +362,14 @@ namespace Js
362362

363363
if (!isClassMethod)
364364
{
365-
prefixString = javascriptLibrary->GetFunctionPrefixString();
365+
prefixString = library->GetFunctionPrefixString();
366366
if (pFuncBody->IsGenerator())
367367
{
368-
prefixString = javascriptLibrary->GetGeneratorFunctionPrefixString();
368+
prefixString = library->GetGeneratorFunctionPrefixString();
369+
}
370+
else if (pFuncBody->IsAsync())
371+
{
372+
prefixString = library->GetAsyncFunctionPrefixString();
369373
}
370374
prefixStringLength = prefixString->GetLength();
371375

test/es6/generators-apis.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function checkAttributes(name, o, p, a) {
2222
}
2323

2424
var tests = [
25-
{
25+
{
2626
name: "GeneratorFunction is not exposed on the global object",
2727
body: function () {
2828
assert.isFalse(globObj.hasOwnProperty("GeneratorFunction"), "Global object does not have property named GeneratorFunction");
@@ -112,7 +112,6 @@ var tests = [
112112
checkAttributes("gfstrict", gfstrict, "caller", { writable: true, enumerable: true, configurable: true });
113113
assert.isTrue(delete gfstrict.caller, "Delete operation on 'caller' property still returns true for a strict mode generator function");
114114
assert.isFalse(gfstrict.hasOwnProperty("caller"), "'caller' property is gone for a strict mode generator function");
115-
116115
}
117116
},
118117
{
@@ -155,12 +154,15 @@ var tests = [
155154

156155
assert.areEqual(Function, Object.getPrototypeOf(generatorFunctionConstructor), "GeneratorFunction's prototype is Function");
157156

157+
assert.isTrue(generatorFunctionConstructor.hasOwnProperty("name"), "GeneratorFunction has 'name' property");
158158
assert.isTrue(generatorFunctionConstructor.hasOwnProperty("length"), "GeneratorFunction has 'length' property");
159159
assert.isTrue(generatorFunctionConstructor.hasOwnProperty("prototype"), "GeneratorFunction has 'prototype' property");
160160

161+
checkAttributes("GeneratorFunction", generatorFunctionConstructor, "name", { writable: false, enumerable: false, configurable: true });
161162
checkAttributes("GeneratorFunction", generatorFunctionConstructor, "length", { writable: false, enumerable: false, configurable: true });
162163
checkAttributes("GeneratorFunction", generatorFunctionConstructor, "prototype", { writable: false, enumerable: false, configurable: false });
163164

165+
assert.areEqual("GeneratorFunction", generatorFunctionConstructor.name, "GeneratorFunction's 'name' property is 'GeneratorFunction'");
164166
assert.areEqual(generatorFunctionPrototype, generatorFunctionConstructor.prototype, "GeneratorFunction's 'prototype' property is GeneratorFunction.prototype");
165167
assert.areEqual(1, generatorFunctionConstructor.length, "GeneratorFunction's 'length' property is 1");
166168
}

test/es6/rlexe.xml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<regress-exe>
3-
<test>
4-
<default>
5-
<files>AsyncAwait-syntax.js</files>
6-
<compile-flags>-es6experimental -nodeferparse -args summary -endargs</compile-flags>
7-
</default>
8-
</test>
9-
<test>
10-
<default>
11-
<files>AsyncAwait-syntax.js</files>
12-
<compile-flags>-es6experimental -forcedeferparse -args summary -endargs</compile-flags>
13-
</default>
14-
</test>
15-
<test>
16-
<default>
17-
<files>AsyncAwait-functionality.js</files>
18-
<compile-flags>-es6experimental -nodeferparse -args summary -endargs</compile-flags>
19-
<baseline>AsyncAwait-functionality.baseline</baseline>
20-
</default>
21-
</test>
22-
<test>
23-
<default>
24-
<files>AsyncAwait-functionality.js</files>
25-
<compile-flags>-es6experimental -forcedeferparse -args summary -endargs</compile-flags>
26-
<baseline>AsyncAwait-functionality.baseline</baseline>
27-
</default>
28-
</test>
293
<test>
304
<default>
315
<files>lambda1.js</files>

0 commit comments

Comments
 (0)