提交 49885b36 编写于 作者: B bianxinbo

api_new2

Signed-off-by: Nbianxinbo <bianxinbo@huawei.com>
上级 ab1e4cd5
......@@ -818,6 +818,44 @@ struct Index {
}
break;
}
case "emitWebMessExtSetError":{
try {
console.log("URL Error");
throw new URIError("URI seq")
}
catch (e) {
console.log("hwd URIError:"+(e instanceof SyntaxError));
console.log("hwd URIError:"+e.message);
console.log("hwd URIError:"+e.name);
if (this.nativePort) {
setTimeout(()=>{
var message =new web_webview.WebMessageExt();
message.setType(web_webview.WebMessageType.ERROR)
this.message.setError(e);
this.nativePort.postMessageEventExt(message);
},2000)
}
}
setTimeout(()=>{
this.controller.runJavaScript("postErrorToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetError() return value is: ${result}`);
Utils.emitEvent(result,515)
})
},3000)
break;
}
case "emitWebMessExtGetError":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postErrorToApp()",(error, result) => {
console.log(`The emitWebMessExtGetError() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
......@@ -993,6 +1031,10 @@ struct Index {
this.msg1 = "result getArrayBuffer byteLength:" + ((result.getArrayBuffer().byteLength));
Utils.emitEvent(this.msg1,514)
}
if(this.type == web_webview.WebMessageType.ERROR){
this.msg1 = "result type:" + typeof (result.getError());
Utils.emitEvent(this.msg1,516)
}
}
catch (resError) {
console.log(`log error code: ${resError.code}, Message: ${resError.message}`);
......
......@@ -581,9 +581,30 @@ export default function webJsunit() {
*tc.desic Save current page
*/
it('WebMessExtGetArrayBuffer',0,async function(done){
emitKey="emitWebMessExtGetArrayBuffer";
emitKey="emitWebMessExtSetError";
Utils.registerEvent("WebMessExtGetArrayBuffer","result getArrayBuffer byteLength:8",514,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_054
*tc.name WebMessExtSetError
*tc.desic Save current page
*/
it('WebMessExtSetError',0,async function(done){
emitKey="emitWebMessExtGetError";
var result="Error:SyntaxError, msg:"
Utils.registerEvent("WebMessExtSetError",JSON.stringify(result),515,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_055
*tc.name WebMessExtGetError
*tc.desic Save current page
*/
it('WebMessExtGetError',0,async function(done){
emitKey="emitWebMessExtGetError";
Utils.registerEvent("WebMessExtGetError","result type:object",516,done);
sendEventByKey('webcomponent',10,'');
})
})
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021~2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -113,13 +113,16 @@ function postArrayBufferToApp() {
}
}
function postErrorToApp() {
if (h5Port) {
console.log("In html send error message");
let err = {name:"cuowu",message:"cuowu"};
h5Port.postMessage(err);
console.log("In html send error message end");
} else {
console.error("In html h5port is null, please init first");
try {
throw new URIError("URI seq 0222")
}
catch (e){
console.log("hwd URIError:"+(e instanceof SyntaxError));
console.log("hwd URIError:"+e.message);
console.log("hwd URIError:"+e.name);
if (h5Port) {
h5Port.postMessage(e);
}
}
}
......@@ -147,4 +150,4 @@ function postArrayBufferToHtml() {
function postErrorToHtml() {
var a=document.getElementById("msg2").innerText
return a
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册