Skip to content

Commit 34acfbd

Browse files
author
Guillaume Chau
committed
Merge branch 'func-proxy-catch'
2 parents 29a0606 + be053bb commit 34acfbd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

shells/dev/target/NativeTypes.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ function setToString (func, string) {
4444
4545
const aWeirdFunction = setToString(function weird (a, b, c) {}, 'foo')
4646
47+
function sum (a, b) {
48+
return a + b
49+
}
50+
51+
const handler = {
52+
apply: function (target, thisArg, argumentsList) {
53+
console.log(`Calculate sum: ${argumentsList}`)
54+
return argumentsList[0] + argumentsList[1]
55+
}
56+
}
57+
58+
const proxy1 = new Proxy(sum, handler)
59+
4760
export default {
4861
components: {
4962
TestComponent: {
@@ -79,7 +92,8 @@ export default {
7992
j: new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])], [8, new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])])]]),
8093
html: '<b>Bold</b> <i>Italic</i>',
8194
htmlReg: /<b>hey<\/b>/i,
82-
'html <b>key</b>': (h, t, m, l) => {}
95+
'html <b>key</b>': (h, t, m, l) => {},
96+
proxy1
8397
}
8498
},
8599
computed: {

src/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ export function getCustomComponentDefinitionDetails (def) {
245245
}
246246

247247
export function getCustomFunctionDetails (func) {
248-
const string = Function.prototype.toString.call(func) || ''
248+
let string = ''
249+
try {
250+
string = Function.prototype.toString.call(func)
251+
} catch (e) {
252+
// Func is probably a Proxy, which can break Function.prototype.toString()
253+
}
249254
const matches = string.match(/\(.*\)/)
250255
const args = matches ? matches[0] : '(?)'
251256
return {

0 commit comments

Comments
 (0)