Skip to content

Commit 71a3562

Browse files
committed
[MERGE #6078 @MikeHolman] remove byteLength from asm.js imports
Merge pull request #6078 from MikeHolman:boundthisbug byteLength was only used for changeHeap, which was removed from asm.js spec. There was bug in how it handled bound this, but since we shouldn't be having it in our list of imports at all, so fixed by removing all the handling for it. Fixes #6052
2 parents c965241 + d7d076d commit 71a3562

File tree

7 files changed

+3
-59
lines changed

7 files changed

+3
-59
lines changed

lib/Runtime/Language/AsmJs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ namespace Js
4848
static bool CheckNewArrayView( AsmJsModuleCompiler &m, PropertyName varName, ParseNode *newExpr );
4949
static bool CheckFunction( AsmJsModuleCompiler &m, ParseNodeFnc* fncNode );
5050
static bool CheckFunctionsSequential(AsmJsModuleCompiler &m);
51-
static bool CheckChangeHeap(AsmJsModuleCompiler &m);
52-
static bool CheckByteLengthCall(AsmJsModuleCompiler &m, ParseNode * node, ParseNode * newBufferDecl);
5351
static bool CheckGlobalVariableInitImport( AsmJsModuleCompiler &m, PropertyName varName, ParseNode *initNode, bool isMutable = true );
5452
static bool CheckGlobalVariableImportExpr(AsmJsModuleCompiler &m, PropertyName varName, AsmJSCoercion coercion, ParseNode *coercedExpr);
5553
static bool CheckFunctionTables(AsmJsModuleCompiler& m);

lib/Runtime/Language/AsmJsBuiltInNames.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
#define ASMJS_MATH_DOUBLE_CONST_NAMES(name, propertyName, value) ASMJS_MATH_CONST_NAMES(name, propertyName, value)
2222
#endif
2323

24-
#ifndef ASMJS_ARRAY_NAMES
25-
#define ASMJS_ARRAY_NAMES(name, propertyName)
26-
#endif
27-
2824
#ifndef ASMJS_TYPED_ARRAY_NAMES
29-
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName) ASMJS_ARRAY_NAMES(name, propertyName)
25+
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName)
3026
#endif
3127

3228
#ifdef ENABLE_JS_BUILTINS
@@ -73,12 +69,10 @@ ASMJS_TYPED_ARRAY_NAMES(Uint32Array, Uint32Array)
7369
ASMJS_TYPED_ARRAY_NAMES(Int32Array, Int32Array)
7470
ASMJS_TYPED_ARRAY_NAMES(Float32Array, Float32Array)
7571
ASMJS_TYPED_ARRAY_NAMES(Float64Array, Float64Array)
76-
ASMJS_ARRAY_NAMES(byteLength, byteLength)
7772

7873
// help the caller to undefine all the macros
7974
#undef ASMJS_JSBUILTIN_MATH_FUNC_NAMES
8075
#undef ASMJS_MATH_FUNC_NAMES
8176
#undef ASMJS_MATH_CONST_NAMES
8277
#undef ASMJS_MATH_DOUBLE_CONST_NAMES
83-
#undef ASMJS_ARRAY_NAMES
8478
#undef ASMJS_TYPED_ARRAY_NAMES

lib/Runtime/Language/AsmJsLink.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,8 @@ namespace Js{
138138

139139
bool ASMLink::CheckArrayLibraryMethod(ScriptContext* scriptContext, const Var stdlib, const AsmJSTypedArrayBuiltinFunction arrayLibMethod)
140140
{
141-
Var arrayFuncObj;
142141
switch (arrayLibMethod)
143142
{
144-
case AsmJSTypedArrayBuiltinFunction::AsmJSTypedArrayBuiltin_byteLength:
145-
arrayFuncObj = JavascriptOperators::OP_GetProperty(stdlib, PropertyIds::byteLength, scriptContext);
146-
if (VarIs<JavascriptFunction>(arrayFuncObj))
147-
{
148-
JavascriptFunction* arrayLibFunc = (JavascriptFunction*)arrayFuncObj;
149-
if (arrayLibFunc->IsBoundFunction())
150-
{
151-
BoundFunction* boundFunc = (BoundFunction*)arrayLibFunc;
152-
RecyclableObject* thisObj = boundFunc->GetBoundThis();
153-
if (VarIs<JavascriptFunction>(thisObj))
154-
{
155-
JavascriptFunction * thisFunc = (JavascriptFunction*)thisObj;
156-
if (thisFunc->GetFunctionInfo()->GetOriginalEntryPoint() != (&ArrayBuffer::EntryInfo::GetterByteLength)->GetOriginalEntryPoint())
157-
{
158-
return false;
159-
}
160-
}
161-
JavascriptFunction* targetFunc = boundFunc->GetTargetFunction();
162-
return targetFunc->GetFunctionInfo()->GetOriginalEntryPoint() == (&JavascriptFunction::EntryInfo::Call)->GetOriginalEntryPoint();
163-
}
164-
}
165-
break;
166143
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName) case AsmJSTypedArrayBuiltinFunction::AsmJSTypedArrayBuiltin_##name: \
167144
return CheckIsBuiltinFunction(scriptContext, stdlib, PropertyIds::##propertyName, propertyName##::EntryInfo::NewInstance);
168145
#include "AsmJsBuiltInNames.h"

lib/Runtime/Language/AsmJsModule.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,27 +1001,6 @@ namespace Js
10011001
return nullptr;
10021002
}
10031003

1004-
bool AsmJsModuleCompiler::CheckByteLengthCall(ParseNode * callNode, ParseNode * bufferDecl)
1005-
{
1006-
if (callNode->nop != knopCall || callNode->AsParseNodeCall()->pnodeTarget->nop != knopName)
1007-
{
1008-
return false;
1009-
}
1010-
AsmJsTypedArrayFunction* arrayFunc = LookupIdentifier<AsmJsTypedArrayFunction>(callNode->AsParseNodeCall()->pnodeTarget->name());
1011-
if (!arrayFunc)
1012-
{
1013-
return false;
1014-
}
1015-
1016-
return callNode->AsParseNodeCall()->argCount == 1 &&
1017-
!callNode->AsParseNodeCall()->isApplyCall &&
1018-
!callNode->AsParseNodeCall()->isEvalCall &&
1019-
callNode->AsParseNodeCall()->spreadArgCount == 0 &&
1020-
arrayFunc->GetArrayBuiltInFunction() == AsmJSTypedArrayBuiltin_byteLength &&
1021-
callNode->AsParseNodeCall()->pnodeArgs->nop == knopName &&
1022-
callNode->AsParseNodeCall()->pnodeArgs->name()->GetPropertyId() == bufferDecl->name()->GetPropertyId();
1023-
}
1024-
10251004
bool AsmJsModuleCompiler::Fail(ParseNode* usepn, const wchar *error)
10261005
{
10271006
AsmJSCompiler::OutputError(GetScriptContext(), error);
@@ -1203,7 +1182,6 @@ namespace Js
12031182
arrayFunctions[AsmJSTypedArrayBuiltin_Uint32Array] = ArrayFunc(PropertyIds::Uint32Array, Anew(&mAllocator, AsmJsTypedArrayFunction, nullptr, &mAllocator, AsmJSTypedArrayBuiltin_Uint32Array, ArrayBufferView::TYPE_UINT32));
12041183
arrayFunctions[AsmJSTypedArrayBuiltin_Float32Array] = ArrayFunc(PropertyIds::Float32Array, Anew(&mAllocator, AsmJsTypedArrayFunction, nullptr, &mAllocator, AsmJSTypedArrayBuiltin_Float32Array, ArrayBufferView::TYPE_FLOAT32));
12051184
arrayFunctions[AsmJSTypedArrayBuiltin_Float64Array] = ArrayFunc(PropertyIds::Float64Array, Anew(&mAllocator, AsmJsTypedArrayFunction, nullptr, &mAllocator, AsmJSTypedArrayBuiltin_Float64Array, ArrayBufferView::TYPE_FLOAT64));
1206-
arrayFunctions[AsmJSTypedArrayBuiltin_byteLength] = ArrayFunc(PropertyIds::byteLength, Anew(&mAllocator, AsmJsTypedArrayFunction, nullptr, &mAllocator, AsmJSTypedArrayBuiltin_byteLength, ArrayBufferView::TYPE_COUNT));
12071185

12081186
for (int i = 0; i < AsmJSTypedArrayBuiltin_COUNT; i++)
12091187
{
@@ -1917,7 +1895,7 @@ namespace Js
19171895
case AsmJsSymbol::TypedArrayBuiltinFunction:
19181896
switch (asmSlot->builtinArrayFunc)
19191897
{
1920-
#define ASMJS_ARRAY_NAMES(name, propertyName) \
1898+
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName) \
19211899
case AsmJSTypedArrayBuiltin_##name: \
19221900
value = JavascriptOperators::OP_GetProperty(stdLibObj, PropertyIds::##propertyName, scriptContext); \
19231901
break;

lib/Runtime/Language/AsmJsModule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ namespace Js {
277277
bool AddStandardLibraryMathName(PropertyId id, AsmJsMathFunction* func, AsmJSMathBuiltinFunction mathLibFunctionName);
278278
bool AddStandardLibraryMathName(PropertyId id, const double* cstAddr, AsmJSMathBuiltinFunction mathLibFunctionName);
279279
bool AddStandardLibraryArrayName(PropertyId id, AsmJsTypedArrayFunction * func, AsmJSTypedArrayBuiltinFunction mathLibFunctionName);
280-
bool CheckByteLengthCall(ParseNode * node, ParseNode * newBufferDecl);
281280
};
282281

283282
template<typename T>

lib/Runtime/Language/AsmJsTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace Js
9090
};
9191
enum AsmJSTypedArrayBuiltinFunction
9292
{
93-
#define ASMJS_ARRAY_NAMES(name, propertyName) AsmJSTypedArrayBuiltin_##name,
93+
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName) AsmJSTypedArrayBuiltin_##name,
9494
#include "AsmJsBuiltInNames.h"
9595
AsmJSTypedArrayBuiltin_COUNT
9696
};

test/AsmJs/relink.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function foo(stdlib, imports, heap)
1414
const b = 3.5;
1515
var inf = stdlib.Infinity;
1616
var I8=stdlib.Int8Array;
17-
var len = stdlib.byteLength;
1817
var ln2 = stdlib.Math.LN2;
1918
var i8= new I8(heap);
2019
var c = fr(4);
@@ -48,7 +47,6 @@ function foo(stdlib, imports, heap)
4847
var table1 = [f, g, f, g];
4948
return {fExp:f, gExp:g};
5049
}
51-
this['byteLength'] = Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get);
5250
var buffer = new ArrayBuffer(1<<24);
5351
var module1 = foo(this, {bar: function f(c){print("import func, val " + c)}, c: 4.5, d: 12}, buffer);
5452
var module2 = foo(this, {bar: function f(c){print("import2 func, val " + c)}, c: 5.5, d: 13}, new ArrayBuffer(1<<25));

0 commit comments

Comments
 (0)