diff --git a/weex_core/Source/core/data_render/binary_file.h b/weex_core/Source/core/data_render/binary_file.h index c6764469e5..9689932554 100644 --- a/weex_core/Source/core/data_render/binary_file.h +++ b/weex_core/Source/core/data_render/binary_file.h @@ -33,6 +33,7 @@ namespace data_render { FUNCTION_SECTION, START_SECTION, GLOBAL_SECTION, + GLOBAL_VARIABLE_SECTION, STYLE_SECTION, ARRAY_SECTION, REF_SECTION, diff --git a/weex_core/Source/core/data_render/exec_state.cc b/weex_core/Source/core/data_render/exec_state.cc index b438575ae5..9ea9a045de 100644 --- a/weex_core/Source/core/data_render/exec_state.cc +++ b/weex_core/Source/core/data_render/exec_state.cc @@ -136,6 +136,7 @@ void ExecState::startEncode() { encodeFunctionSection(); encodeStartSection(); encodeGlobalSection(); + encodeGlobalVariableSection(); encodeStyleSection(); encodeArraySection(); encodeRefSection(); @@ -220,6 +221,10 @@ void ExecState::encodeFunctionSection() { super_index = static_cast(it - func_states.begin()); } file->write((char*)&super_index, sizeof(int)); + + bool is_class_func = func_state->is_class_func(); + file->write((char*)&is_class_func, sizeof(int)); + unsigned opcodeSize = static_cast(func_state->instructions().size()); file->write((char*)&opcodeSize, sizeof(unsigned)); for (int i=0; i(global_variables_.size()); + + file->write((char*)&id, sizeof(unsigned)); + file->write((char*)&size, sizeof(unsigned)); + for (auto variable : global_variables_) { + unsigned length = static_cast(variable.first.length()) + 1; + file->write(variable.first.c_str(), static_cast(sizeof(char) * length)); + file->write((char*)&variable.second, sizeof(long)); + } +} + void ExecState::encodeStyleSection() { unsigned id = Section::STYLE_SECTION; std::map& styles = render_context_->style_json(); @@ -490,6 +509,9 @@ bool ExecState::startDecode() { case GLOBAL_SECTION: decodeGlobalSection(); break; + case GLOBAL_VARIABLE_SECTION: + decodeGlobalVariableSection(); + break; case STYLE_SECTION: decodeStyleSection(); break; @@ -580,6 +602,10 @@ void ExecState::decodeFunctionSection() { file->read((char*)&super_index, sizeof(int)); func_state->set_super_index(super_index); + bool is_class_func = false; + file->read((char*)&is_class_func, sizeof(bool)); + func_state->set_is_class_func(is_class_func); + unsigned op_code_count = 0; file->read((char*)&op_code_count, sizeof(unsigned)); for (int j=0; jread((char*)&count, sizeof(unsigned)); + if (count == 0) { + return; + } + + for (int i=0; iread(&c, sizeof(char)); + if (c == 0) { + break; + } + key += c; + } + + long value; + file->read((char*)&value, sizeof(long)); + global_variables_.insert(std::pair(key, value)); + } +} + void ExecState::decodeStyleSection() { BinaryFile* file = BinaryFile::instance(); diff --git a/weex_core/Source/core/data_render/exec_state.h b/weex_core/Source/core/data_render/exec_state.h index fbe6866bbe..a256572ac9 100644 --- a/weex_core/Source/core/data_render/exec_state.h +++ b/weex_core/Source/core/data_render/exec_state.h @@ -167,6 +167,7 @@ class ExecState { friend class CodeGenerator; void encodeGlobalSection(); + void encodeGlobalVariableSection(); void encodeFunctionSection(); void encodeStartSection(); void encodeTableSection(); @@ -183,6 +184,7 @@ class ExecState { void decodeFunctionSection(); void decodeStartSection(); void decodeGlobalSection(); + void decodeGlobalVariableSection(); void decodeStyleSection(); void decodeArraySection(); void decodeRefSection();