Default parameters on async functions do not work in Safari
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, python
- 领域
- compilers
调研方向
No source file or test is named. Start by reproducing the generated functions in Safari and comparing the async and regular-function output, then locate the compiler path that emits default-parameter handling. Done means async functions with default parameters produce the expected results in Safari without redeclaring an existing parameter.
由索引模型根据 Issue 内容生成。
描述
Consider these two functions.
def multiply(a, b=1):
return a * b
async def multiply_async(a, b=1):
return a * b
Compiled to JS, they are:
// Transcrypt'ed from Python, 2024-09-01 01:05:45
import {AssertionError, AttributeError, BaseException, DeprecationWarning, Exception, IndexError, IterableError, KeyError, NotImplementedError, RuntimeWarning, StopIteration, UserWarning, ValueError, Warning, __JsIterator__, __PyIterator__, __Terminal__, __add__, __and__, __call__, __class__, __envir__, __eq__, __floordiv__, __ge__, __get__, __getcm__, __getitem__, __getslice__, __getsm__, __gt__, __i__, __iadd__, __iand__, __idiv__, __ijsmod__, __ilshift__, __imatmul__, __imod__, __imul__, __in__, __init__, __ior__, __ipow__, __irshift__, __isub__, __ixor__, __jsUsePyNext__, __jsmod__, __k__, __kwargtrans__, __le__, __lshift__, __lt__, __matmul__, __mergefields__, __mergekwargtrans__, __mod__, __mul__, __ne__, __neg__, __nest__, __or__, __pow__, __pragma__, __pyUseJsNext__, __rshift__, __setitem__, __setproperty__, __setslice__, __sort__, __specialattrib__, __sub__, __super__, __t__, __terminal__, __truediv__, __withblock__, __xor__, _sort, abs, all, any, assert, bin, bool, bytearray, bytes, callable, chr, delattr, dict, dir, divmod, enumerate, filter, float, getattr, hasattr, hex, input, int, isinstance, issubclass, len, list, map, max, min, object, oct, ord, pow, print, property, py_TypeError, py_iter, py_metatype, py_next, py_reversed, py_typeof, range, repr, round, set, setattr, sorted, str, sum, tuple, zip} from './org.transcrypt.__runtime__.js';
var __name__ = '__main__';
export var multiply = function (a, b) {
if (typeof b == 'undefined' || (b != null && b.hasOwnProperty ("__kwargtrans__"))) {;
var b = 1;
};
return a * b;
};
export var multiply_async = async function (a, b) {
if (typeof b == 'undefined' || (b != null && b.hasOwnProperty ("__kwargtrans__"))) {;
var b = 1;
};
return a * b;
};
Now, let's test those 2 functions:
console.log('multiply')
console.log(multiply(5, 2))
console.log(multiply(5))
console.log('multiply_async:')
multiply_async(5, 2).then(console.log)
multiply_async(5).then(console.log)
In Chrome and Node, the output is:
multiply:
10
5
multiply_async:
10
5
But in Safari, the output is:
multiply:
10
5
multiply_async:
5
5
This is due to redeclaring b (var b = 1;), when b was already defined as the parameter of the function. In normal written Javascript, we would just reassign (b = 1).
Someone else has noticed this before:
https://medium.com/@alsotang/a-hoisting-bug-in-the-async-function-in-safari-ba1ecc386b4a
Therefore, it is not safe to re-declare function parameters using var
- 主要语言
- Python
- 星标
- 2.9k
- 派生
- 218
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TranscryptOrg/Transcrypt 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
TranscryptOrg/Transcrypt#913 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
TranscryptOrg/Transcrypt#911 · 2 条评论 ·
-
IS: bug
难度 2/5 1-3 小时 新手友好度 70/100
TranscryptOrg/Transcrypt#908 ·
-
Update installation and testing instructions可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭SUB: documentation
难度 1/5 1 小时以内 新手友好度 62/100
TranscryptOrg/Transcrypt#656 · 7 条评论 ·
-
re: character classes are parsed as regular expressions可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 76/100
TranscryptOrg/Transcrypt#914 ·
查看 TranscryptOrg/Transcrypt 的全部 Issue
相似的 Issue
-
dead_air_detection fails on m4a/AAC audio ("Could not decode audio: Format not recognised") for uploads, base64 and own-bucket recordings可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
future-agi/future-agi#3317 ·
维护者通常 1 天内回复
-
Failed agent type collection replaces a complete snapshot with partial data可能已有人在做 @SahilKumar75 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 2 天内回复
-
task
难度 2/5 半天 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#133181 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
bmad-code-org/BMAD-METHOD#3041 ·
维护者通常 1 天内回复