Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
renderjs
Commits
228c010f
Commit
228c010f
authored
Nov 22, 2021
by
Gabriel Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve output error to AcquisitionError and CancelationError
parent
7aa02017
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
16 deletions
+114
-16
renderjs.js
renderjs.js
+71
-4
test/embedded.js
test/embedded.js
+6
-2
test/renderjs_test.js
test/renderjs_test.js
+37
-10
No files found.
renderjs.js
View file @
228c010f
...
...
@@ -61,6 +61,19 @@
ScopeError
.
prototype
=
new
Error
();
ScopeError
.
prototype
.
constructor
=
ScopeError
;
/////////////////////////////////////////////////////////////////
// renderJS.IframeSerializationError
/////////////////////////////////////////////////////////////////
function
IframeSerializationError
(
message
)
{
this
.
name
=
"
IframeSerializationError
"
;
if
((
message
!==
undefined
)
&&
(
typeof
message
!==
"
string
"
))
{
throw
new
TypeError
(
'
You must pass a string.
'
);
}
this
.
message
=
message
||
"
IframeSerialization Error
"
;
}
IframeSerializationError
.
prototype
=
new
Error
();
IframeSerializationError
.
prototype
.
constructor
=
IframeSerializationError
;
function
ensurePushableQueue
(
callback
,
argument_list
,
context
)
{
var
result
;
try
{
...
...
@@ -208,6 +221,7 @@
isAbsoluteOrDataURL
=
new
RegExp
(
'
^(?:[a-z]+:)?//|data:
'
,
'
i
'
),
is_page_unloaded
=
false
,
error_list
=
[],
unhandled_error_type
=
2
,
all_dependency_loaded_deferred
;
window
.
addEventListener
(
'
error
'
,
function
handleGlobalError
(
error
)
{
...
...
@@ -257,6 +271,28 @@
return
url
;
}
function
getErrorTypeMapping
()
{
var
error_type_mapping
=
{
0
:
renderJS
.
AcquisitionError
,
1
:
RSVP
.
CancellationError
};
// set the unhandle error type to be used as default
error_type_mapping
[
unhandled_error_type
]
=
IframeSerializationError
;
return
error_type_mapping
;
}
function
convertObjectToErrorType
(
error
)
{
var
error_type
,
error_type_mapping
=
getErrorTypeMapping
();
for
(
error_type
in
error_type_mapping
)
{
if
(
error_type_mapping
.
hasOwnProperty
(
error_type
)
&&
error
instanceof
error_type_mapping
[
error_type
])
{
return
error_type
;
}
}
return
unhandled_error_type
;
}
function
letsCrash
(
e
)
{
var
i
,
body
,
...
...
@@ -1025,13 +1061,25 @@
channel_call_id
,
wait_promise
=
new
RSVP
.
Promise
(
function
handleChannelCall
(
resolve
,
reject
)
{
function
error_wrap
(
value
)
{
var
error_type_mapping
=
getErrorTypeMapping
();
if
(
value
.
hasOwnProperty
(
"
type
"
)
&&
error_type_mapping
.
hasOwnProperty
(
value
.
type
))
{
return
reject
(
new
error_type_mapping
[
value
.
type
](
value
.
msg
));
}
return
reject
(
value
);
}
channel_call_id
=
gadget_instance
.
__chan
.
call
({
method
:
"
methodCall
"
,
params
:
[
method_name
,
Array
.
prototype
.
slice
.
call
(
argument_list
,
0
)],
success
:
resolve
,
error
:
reject
error
:
error_wrap
});
},
function
cancelChannelCall
(
msg
)
{
...
...
@@ -1071,7 +1119,10 @@
})
.
then
(
trans
.
complete
)
.
fail
(
function
handleChannelAcquireError
(
e
)
{
trans
.
error
(
e
.
toString
());
trans
.
error
({
type
:
convertObjectToErrorType
(
e
),
msg
:
e
.
message
});
});
trans
.
delayReturn
(
true
);
});
...
...
@@ -1595,6 +1646,7 @@
/////////////////////////////////////////////////////////////////
renderJS
.
Mutex
=
Mutex
;
renderJS
.
ScopeError
=
ScopeError
;
renderJS
.
IframeSerializationError
=
IframeSerializationError
;
renderJS
.
loopEventListener
=
loopEventListener
;
window
.
rJS
=
window
.
renderJS
=
renderJS
;
window
.
__RenderJSGadget
=
RenderJSGadget
;
...
...
@@ -1901,6 +1953,17 @@
time_out
)
{
return
new
RSVP
.
Promise
(
function
waitForChannelAcquire
(
resolve
,
reject
)
{
function
error_wrap
(
value
)
{
var
error_type_mapping
=
getErrorTypeMapping
();
if
(
value
.
hasOwnProperty
(
"
type
"
)
&&
error_type_mapping
.
hasOwnProperty
(
value
.
type
))
{
value
=
new
error_type_mapping
[
value
.
type
](
value
.
msg
);
}
return
reject
(
value
);
}
embedded_channel
.
call
({
method
:
"
acquire
"
,
params
:
[
...
...
@@ -1908,7 +1971,7 @@
argument_list
],
success
:
resolve
,
error
:
reject
,
error
:
error_wrap
,
timeout
:
time_out
});
}
...
...
@@ -1925,9 +1988,13 @@
delete
transaction_dict
[
transaction_id
];
trans
.
complete
.
apply
(
trans
,
arguments
);
},
function
handleMethodCallError
(
e
)
{
var
error
=
{
type
:
convertObjectToErrorType
(
e
),
msg
:
e
.
message
};
// drop the promise reference, to allow garbage collection
delete
transaction_dict
[
transaction_id
];
trans
.
error
(
e
.
toString
()
);
trans
.
error
(
e
rror
);
});
trans
.
delayReturn
(
true
);
});
...
...
test/embedded.js
View file @
228c010f
...
...
@@ -117,7 +117,9 @@
if
(
error
instanceof
renderJS
.
AcquisitionError
)
{
throw
error
;
}
throw
new
Error
(
'
Expected AcquisitionError:
'
+
error
);
throw
new
Error
(
'
Expected AcquisitionError:
'
+
JSON
.
stringify
(
error
)
);
});
})
.
declareMethod
(
'
triggerMethodToCancel
'
,
function
()
{
...
...
@@ -139,7 +141,9 @@
acquired_method_cancel_called
=
true
;
throw
error
;
}
throw
new
Error
(
'
Expected CancellationError:
'
+
error
);
throw
new
Error
(
'
Expected CancellationError:
'
+
JSON
.
stringify
(
error
)
);
});
})
.
declareMethod
(
'
wasAcquiredMethodCancelCalled
'
,
function
()
{
...
...
test/renderjs_test.js
View file @
228c010f
...
...
@@ -5671,7 +5671,7 @@
gadget
.
__sub_gadget_dict
=
{};
stop
();
expect
(
2
8
);
expect
(
2
9
);
gadget
.
declareGadget
(
url
,
{
sandbox
:
'
iframe
'
,
element
:
document
.
getElementById
(
'
qunit-fixture
'
),
...
...
@@ -5797,7 +5797,11 @@
.
push
(
function
()
{
ok
(
false
,
"
triggerError should fail
"
);
},
function
(
e
)
{
equal
(
e
,
"
Error: Manually triggered embedded error
"
);
ok
(
e
instanceof
renderJS
.
IframeSerializationError
);
equal
(
e
.
toString
(),
"
IframeSerializationError: Manually triggered embedded error
"
);
})
// sub_gadget_dict private property is created
...
...
@@ -5844,7 +5848,10 @@
ok
(
false
,
result
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
error
instanceof
renderJS
.
AcquisitionError
,
error
);
ok
(
error
instanceof
renderJS
.
AcquisitionError
,
JSON
.
stringify
(
error
)
);
})
// cancel is correctly propagated by declareMethod
...
...
@@ -5871,7 +5878,7 @@
return
new_gadget
.
triggerAcquiredMethodToCancel
();
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
error
instanceof
RSVP
.
CancellationError
,
error
);
ok
(
error
instanceof
RSVP
.
CancellationError
,
JSON
.
stringify
(
error
)
);
return
new_gadget
.
wasAcquiredMethodCancelCalled
();
})
.
push
(
function
(
result
)
{
...
...
@@ -5925,7 +5932,7 @@
gadget
.
__sub_gadget_dict
=
{};
stop
();
expect
(
1
6
);
expect
(
1
9
);
gadget
.
declareGadget
(
url
,
{
sandbox
:
'
iframe
'
,
element
:
document
.
getElementById
(
'
qunit-fixture
'
)
...
...
@@ -5985,7 +5992,11 @@
.
push
(
function
()
{
ok
(
false
,
"
triggerError should fail
"
);
},
function
(
e
)
{
equal
(
e
,
"
Error: Manually triggered embedded error
"
);
ok
(
e
instanceof
renderJS
.
IframeSerializationError
);
equal
(
e
.
toString
(),
"
IframeSerializationError: Manually triggered embedded error
"
);
})
// sub_gadget_dict private property is created
...
...
@@ -6032,12 +6043,18 @@
ok
(
false
,
result
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
error
instanceof
renderJS
.
AcquisitionError
);
equal
(
error
,
error
.
toString
()
,
"
AcquisitionError: Can not handle
"
+
"
acquireMethodRequestedWithAcquisitionError
"
,
error
);
equal
(
error
.
name
,
"
AcquisitionError
"
,
error
);
});
})
.
fail
(
function
(
error
)
{
...
...
@@ -6072,7 +6089,7 @@
gadget
.
__sub_gadget_dict
=
{};
stop
();
expect
(
1
6
);
expect
(
1
9
);
gadget
.
declareGadget
(
url
,
{
sandbox
:
'
iframe
'
,
element
:
document
.
getElementById
(
'
qunit-fixture
'
)
...
...
@@ -6132,7 +6149,11 @@
.
push
(
function
()
{
ok
(
false
,
"
triggerError should fail
"
);
},
function
(
e
)
{
equal
(
e
,
"
Error: Manually triggered embedded error
"
);
ok
(
e
instanceof
renderJS
.
IframeSerializationError
);
equal
(
e
.
toString
(),
"
IframeSerializationError: Manually triggered embedded error
"
);
})
// sub_gadget_dict private property is created
...
...
@@ -6179,12 +6200,18 @@
ok
(
false
,
result
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
error
instanceof
renderJS
.
AcquisitionError
,
error
);
equal
(
error
,
error
.
toString
()
,
"
AcquisitionError: Can not handle
"
+
"
acquireMethodRequestedWithAcquisitionError
"
,
error
);
equal
(
error
.
name
,
"
AcquisitionError
"
,
error
);
});
})
.
fail
(
function
(
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment