You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2018/11/27 06:27:33 UTC

[GitHub] jianhan-he closed pull request #1801: [core] add script section in opcode file

jianhan-he closed pull request #1801: [core] add script section in opcode file
URL: https://github.com/apache/incubator-weex/pull/1801
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 4a04c1443b..3cd20f9b8a 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -485,7 +485,7 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
         newOptions[bundleUrlOptionKey] = url.absoluteString;
     }
 
-    if ([url.absoluteString hasSuffix:WEEX_LITE_URL_SUFFIX]) {
+    if ([url.absoluteString hasSuffix:WEEX_LITE_URL_SUFFIX] || [url.absoluteString containsString:@"__eagle=true"]) {
         newOptions[@"WLASM_RENDER"] = @(YES);
     }
 
@@ -549,7 +549,7 @@ - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)
             return;
         }
         
-        if (([options[@"DATA_RENDER"] boolValue] && [options[@"RENDER_WITH_BINARY"] boolValue]) || [options[@"WLASM_RENDER"] boolValue]) {
+        if (([newOptions[@"DATA_RENDER"] boolValue] && [newOptions[@"RENDER_WITH_BINARY"] boolValue]) || [newOptions[@"WLASM_RENDER"] boolValue]) {
             [strongSelf _renderWithData:data];
             return;
         }
diff --git a/weex_core/Source/core/data_render/exec_state_binary.cc b/weex_core/Source/core/data_render/exec_state_binary.cc
index 0b19a00818..6c57c81053 100644
--- a/weex_core/Source/core/data_render/exec_state_binary.cc
+++ b/weex_core/Source/core/data_render/exec_state_binary.cc
@@ -69,6 +69,11 @@ bool ExecStateEncoder::encoding(std::string &err) {
                 err = "data section encoding error";
                 break;
             }
+            SectionScript script(this);
+            if (!script.encoding()) {
+                err = "script section encoding error";
+                break;
+            }
             SectionFunction function(this, gs_op_code_bits);
             if (!function.encoding()) {
                 err = "function section encoding error";
@@ -160,6 +165,14 @@ bool ExecStateDecoder::decoding(std::string &err) {
                         }
                         break;
                     }
+                    case ExecSection::EXEC_SECTION_SCRIPT:
+                    {
+                        SectionScript script(this, section_length);
+                        if (!script.decoding()) {
+                            throw EncoderError("script section decoding error");
+                        }
+                        break;
+                    }
                     case ExecSection::EXEC_SECTION_FUNCTION:
                     {
                         SectionFunction function(this, gs_op_code_bits, section_length);
diff --git a/weex_core/Source/core/data_render/exec_state_section.cc b/weex_core/Source/core/data_render/exec_state_section.cc
index b68ea2f068..22ade17194 100644
--- a/weex_core/Source/core/data_render/exec_state_section.cc
+++ b/weex_core/Source/core/data_render/exec_state_section.cc
@@ -1274,6 +1274,69 @@ bool SectionData::decoding() {
     
     return finished;
 }
+
+uint32_t SectionScript::size() {
+    ExecState *exec_state = encoder()->exec_state();
+    const json11::Json& script = exec_state->context()->raw_json()["script"];
+    std::string script_string = script.string_value();
+    uint32_t size = 0;
+    if (!script_string.empty()) {
+        size += GetFTLVLength(kValueScriptPayload, (uint32_t)script_string.length());
+    }
+    return size;
+}
+
+bool SectionScript::encoding() {
+    uint32_t size = this->size();
+    if (!size) {
+        return true;
+    }
+    if (!Section::encoding((uint16_t)ExecSection::EXEC_SECTION_SCRIPT, size)) {
+        return false;
+    }
+    ExecState *exec_state = encoder()->exec_state();
+    const json11::Json& script = exec_state->context()->raw_json()["script"];
+    std::string script_string = script.string_value();
+
+    uint32_t length = (uint32_t)script_string.length();
+    if (!Section::encoding(kValueScriptPayload, length, (void *)script_string.c_str())) {
+        return false;
+    }
+    return true;
+}
+
+bool SectionScript::decoding() {
+    fStream *stream = Section::stream();
+    if (!stream) {
+        return false;
+    }
+    if (stream->Tell() < 0) {
+        return false;
+    }
+    uint16_t vindex = 0;
+    uint32_t varlen = stream->ReadTarget(&vindex, NULL, NULL);
+    if (vindex != kValueScriptPayload) {
+        return false;
+    }
+    if (varlen == 0) {
+        std::string str = "";
+        decoder()->exec_state()->context()->set_script(str);
+        return true;
+    }
+    char *pstr = (char *)malloc(varlen + 1);
+    if (!pstr) {
+        return false;
+    }
+    memset(pstr, 0, varlen + 1);
+    if (stream->Read(pstr, 1, varlen) != varlen) {
+        return false;
+    }
+    decoder()->exec_state()->context()->set_script(pstr);
+    LOGD("decoding script:%s\n", pstr);
+    free(pstr);
+
+    return true;
+}
     
 uint32_t SectionFunction::GetInstructionsBytes(std::vector<Instruction>& instructions) {
     uint32_t numBits = 0;
@@ -2312,7 +2375,7 @@ bool SectionStyles::decoding() {
             size = sizeof(uint32_t);
             uint32_t items_size = 0;
             readbytes = stream->ReadTarget(&target, (uint8_t *)&items_size, &size);
-            if (!readbytes || target != kValueStyleItemSize || !items_size) {
+            if (!readbytes || target != kValueStyleItemSize) {
                 throw DecoderError("decoding styles items size error");
                 break;
             }
diff --git a/weex_core/Source/core/data_render/exec_state_section.h b/weex_core/Source/core/data_render/exec_state_section.h
index 1e1e3ceb52..7bb22a2abe 100644
--- a/weex_core/Source/core/data_render/exec_state_section.h
+++ b/weex_core/Source/core/data_render/exec_state_section.h
@@ -44,7 +44,8 @@ enum ExecSection {
     EXEC_SECTION_GLOBAL_VARIABLES,
     EXEC_SECTION_STYLES,
     EXEC_SECTION_VALUEREF,
-    EXEC_SECTION_CLASS
+    EXEC_SECTION_CLASS,
+    EXEC_SECTION_SCRIPT
 };
 
 class fStream;
@@ -125,6 +126,19 @@ class SectionData : public Section {
     virtual bool decoding();
     virtual uint32_t size();
 };
+
+class SectionScript : public Section {
+public:
+    enum SectionKey {
+        kValueScriptPayload
+    };
+    SectionScript(ExecStateEncoder *encoder) : Section(encoder) {}
+    SectionScript(ExecStateDecoder *decoder, uint32_t length) : Section(decoder, length) {}
+    virtual ~SectionScript() {};
+    virtual bool encoding();
+    virtual bool decoding();
+    virtual uint32_t size();
+};
     
 class SectionFunction : public Section {
 public:


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services