[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[core] fix bugs in data render mode (#1613)
Browse files Browse the repository at this point in the history
* [core] bugfix ' ' url_encode =>  '%20'

* [core] bugfix supporting function varying parameter

* [core] bugfix add utf8 decode for string tokenizer parsing

* [core] data_render output error log

* [core] fix event invalid in opcode

* [core] opcode supprot big endian

* [core] modify int to int32_t and unsigned to u_int32_t

* [core] add argc in opcode
  • Loading branch information
yxping authored and YorkShen committed Oct 2, 2018
1 parent a4efea0 commit d4cd1eb
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,9 @@ public void fireEventOnNode(final String instanceId, final String ref,
throw new WXRuntimeException(
"fireEvent must be called by main thread");
}
if (WXSDKManager.getInstance().getAllInstanceMap().get(instanceId)!=null && WXSDKManager.getInstance().getAllInstanceMap().get(instanceId).getRenderStrategy()== WXRenderStrategy.DATA_RENDER) {
WXSDKInstance instance = WXSDKManager.getInstance().getAllInstanceMap().get(instanceId);
if (instance != null && (instance.getRenderStrategy() == WXRenderStrategy.DATA_RENDER ||
instance.getRenderStrategy() == WXRenderStrategy.DATA_RENDER_BINARY)) {
fireEventOnDataRenderNode(instanceId, ref, type, data);
} else {
if(callback == null) {
Expand Down
12 changes: 10 additions & 2 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,16 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict,

void IOSSide::ReportException(const char* pageId, const char *func, const char *exception_string)
{
// should not enter this function
assert(false);
NSString* ns_instanceId = NSSTRING(pageId);

WXComponentManager* manager = [WXSDKManager instanceForID:ns_instanceId].componentManager;
if (!manager.isValid) {
return;
}

int wxErrorCode = 9999;
NSError * error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:wxErrorCode userInfo:@{@"message":[NSString stringWithUTF8String:exception_string]}];
[manager renderFailed:error];
}

int IOSSide::CallNative(const char* pageId, const char *task, const char *callback)
Expand Down
5 changes: 5 additions & 0 deletions ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ void WXPerformBlockSyncOnComponentThread(void (^block)(void));
**/
- (void)renderFinish;

/**
* @abstract called when render failed
**/
- (void)renderFailed:(NSError *)error;

/**
* @abstract unload
**/
Expand Down
11 changes: 11 additions & 0 deletions ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,17 @@ - (void)renderFinish
}];
}

- (void)renderFailed:(NSError *)error {
WXAssertComponentThread();

WXSDKInstance *instance = self.weexInstance;
[self _addUITask:^{
if (instance.onFailed) {
instance.onFailed(error);
}
}];
}

- (void)unload
{
WXAssertComponentThread();
Expand Down
23 changes: 20 additions & 3 deletions weex_core/Source/core/data_render/binary_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
*/

#include "core/data_render/binary_file.h"
#include "core/data_render/common_error.h"

namespace weex {
namespace core {
namespace data_render {
BinaryFile* BinaryFile::g_instance_ = nullptr;

BinaryFile::BinaryFile():fout_(nullptr), position_(0), length_(0){
BinaryFile::BinaryFile():fout_(nullptr), position_(0), length_(0) {
int32_t i=1;
char *b=(char *)&i;
if (*b == 1) {
little_endian_ = true;
} else {
little_endian_ = false;
}
}

BinaryFile* BinaryFile::instance() {
Expand All @@ -51,8 +59,17 @@ namespace data_render {
}

void BinaryFile::read(char *stream, unsigned count) {
for (int i=0; i<count; i++) {
stream[i] = input_[position_++];
if (position_ + count > length_) {
throw OpcodeDecodeError("Read data is error");
}
if (!little_endian_ && count > 1) {
for (int i=count-1; i>=0; i--) {
stream[i] = input_[position_++];
}
} else {
for (int i=0; i<count; i++) {
stream[i] = input_[position_++];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/data_render/binary_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace data_render {
const char* input_;
unsigned long position_;
unsigned long length_;
bool little_endian_;
};
} // namespace data_render
} // namespace core
Expand Down
69 changes: 68 additions & 1 deletion weex_core/Source/core/data_render/class_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ char *url_encode(char *str) {
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
*pbuf++ = *pstr;
else if (*pstr == ' ')
*pbuf++ = '+';
*pbuf++ = '%', *pbuf++ = '2', *pbuf++ = '0';
else
*pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
pstr++;
Expand Down Expand Up @@ -230,6 +230,73 @@ Value encodeURIComponent(ExecState *exec_state) {
}
return exec_state->string_table()->StringFromUTF8(dst);
}

std::string utf8chr(int cp)
{
char c[5] = { 0x00,0x00,0x00,0x00,0x00 };
if (cp <= 0x7F) {
c[0] = cp;
}
else if (cp <= 0x7FF) {
c[0] = (cp >> 6) + 192;
c[1] = (cp & 63) + 128;
}
else if (0xd800 <= cp && cp <= 0xdfff) {
//invalid block of utf8
}
else if (cp <= 0xFFFF)
{
c[0] = (cp >> 12) + 224;
c[1]= ((cp >> 6) & 63) + 128;
c[2] = (cp & 63) + 128;
}
else if (cp <= 0x10FFFF) {
c[0] = (cp >> 18) + 240;
c[1] = ((cp >> 12) & 63) + 128;
c[2] = ((cp >> 6) & 63) + 128;
c[3] = (cp & 63) + 128;
}
return std::string(c);
}

std::string utf8_decode(std::string &input) {
do {
size_t length = input.length();
if (!length) {
break;
}
const char *chars = input.c_str();
std::string utf8str = "";
for (int i = 0; i < length; i++) {
char c = chars[i];
if (c == '\\' && chars[i + 1] == 'u') {
int cc = 0;
for (int j = 0; j < 4; j++)
{
char ch = tolower(chars[i + 2 + j]);
if (('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f')) {
cc|= (from_hex(ch) << (3 - j) * 4);
}
else
{
cc = 0;
break;
}
}
if (cc) {
i += 5;
utf8str += utf8chr(cc);
continue;
}
}
utf8str.push_back(c);
}
return utf8str;

} while (0);

return input;
}

Value indexOf(ExecState* exec_state) {
size_t length = exec_state->GetArgumentCount();
Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/data_render/class_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace data_render {

ClassDescriptor *NewClassString();
Value encodeURIComponent(ExecState *exec_state);
std::string utf8_decode(std::string &input);

} // namespace data_render
} // namespace core
Expand Down
5 changes: 5 additions & 0 deletions weex_core/Source/core/data_render/code_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,12 @@ void CodeGenerator::Visit(FunctionStatement *node, void *data) {
// make arguments var in thie front of stack;
if (is_class_func) {
block_->AddVariable("this", block_->NextRegisterId());
func_->func_state()->argc()++;
}
for (int i = 0; i < proto->GetArgs().size(); i++) {
std::string arg = proto->GetArgs().at(i);
block_->AddVariable(arg, block_->NextRegisterId());
func_->func_state()->argc()++;
}
node->body()->Accept(this, nullptr);
}
Expand Down Expand Up @@ -505,18 +507,21 @@ void CodeGenerator::Visit(ArrowFunctionStatement *node, void *data) {
// make arguments var in thie front of stack;
if (is_class_func) {
block_->AddVariable("this", block_->NextRegisterId());
func_->func_state()->argc()++;
}
// make arguments var in thie front of stack;
for (int i = 0; i < node->args().size(); i++) {
if (node->args()[i]->IsIdentifier()) {
std::string arg = node->args()[i]->AsIdentifier()->GetName();
block_->AddVariable(arg, block_->NextRegisterId());
func_->func_state()->argc()++;
}
else if (node->args()[i]->IsCommaExpression()) {
Handle<ExpressionList> arg_list = node->args()[i]->AsCommaExpression()->exprs();
for (int j = 0; j < arg_list->Size(); j++) {
std::string arg = arg_list->raw_list()[j]->AsIdentifier()->GetName();
block_->AddVariable(arg, block_->NextRegisterId());
func_->func_state()->argc()++;
}
}
else {
Expand Down
6 changes: 6 additions & 0 deletions weex_core/Source/core/data_render/common_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class VMExecError : public Error {
VMExecError(std::string str)
: Error("[VMExecError]", std::move(str)) { }
};

class OpcodeDecodeError : public Error {
public:
OpcodeDecodeError(std::string str)
: Error("[OpcodeDecodeError]", std::move(str)) { }
};

class SyntaxError : public JSError {
public:
Expand Down
Loading

0 comments on commit d4cd1eb

Please sign in to comment.