Skip to content

Commit

Permalink
fix: remove logs and fix normal cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jul 11, 2024
1 parent 6feb3f0 commit 21cbb0f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion bridge/core/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void evaluateWbcInternal(void* page_,
WEBF_LOG(VERBOSE) << "LZ4 decompression success! " << decompressedSize << std::endl;
#endif
is_success = page->evaluateByteCode(reinterpret_cast<uint8_t*>(decompressedBytes.data()), decompressedSize);
WEBF_LOG(VERBOSE) << " SUCCESS: " << is_success;
}
}

Expand Down
19 changes: 13 additions & 6 deletions bridge/core/html/parser/html_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void HTMLParser::traverseHTML(Node* root_node, GumboNode* node) {
auto* html_element = DynamicTo<Element>(root_node);
if (html_element != nullptr && html_element->localName() == html_names::khtml) {
bool _ = false;
parseProperty(html_element, &node->v.element, &_);
parseProperty(html_element, &node->v.element, &_, &_);
}

const GumboVector* children = &node->v.element.children;
Expand Down Expand Up @@ -136,9 +136,10 @@ void HTMLParser::traverseHTML(Node* root_node, GumboNode* node) {
}

bool is_script_element = child->v.element.tag == GumboTag::GUMBO_TAG_SCRIPT;
bool is_standard_script_element = false;
bool is_wbc_script_element;
parseProperty(element, &child->v.element, &is_wbc_script_element);
if (is_script_element) {
parseProperty(element, &child->v.element, &is_wbc_script_element, &is_standard_script_element);
if (is_script_element && child->v.element.children.length > 0) {
auto& gumbo_script_element = child->v.element;
assert(gumbo_script_element.children.length == 1);
auto* script_text_node = (GumboNode*)gumbo_script_element.children.data[0];
Expand Down Expand Up @@ -246,19 +247,25 @@ void HTMLParser::freeSVGResult(GumboOutput* svgTree) {
gumbo_destroy_output(&kGumboDefaultOptions, svgTree);
}

void HTMLParser::parseProperty(Element* element, GumboElement* gumboElement, bool* is_wbc_scripts_element) {
void HTMLParser::parseProperty(Element* element, GumboElement* gumboElement, bool* is_wbc_scripts_element, bool* is_standard_script_element) {
auto* context = element->GetExecutingContext();
JSContext* ctx = context->ctx();

bool is_script_element = gumboElement->tag == GumboTag::GUMBO_TAG_SCRIPT;

GumboVector* attributes = &gumboElement->attributes;
for (int j = 0; j < attributes->length; ++j) {
auto* attribute = (GumboAttribute*)attributes->data[j];

std::string strName = attribute->name;
std::string strValue = attribute->value;

if (strName == "type" && strValue == "application/vnd.webf.bc1") {
*is_wbc_scripts_element = true;
if (is_script_element) {
if (strName == "type" && strValue == "application/vnd.webf.bc1") {
*is_wbc_scripts_element = true;
} else {
*is_standard_script_element = true;
}
}

element->setAttribute(AtomicString(ctx, strName), AtomicString(ctx, strValue), ASSERT_NO_EXCEPTION());
Expand Down
2 changes: 1 addition & 1 deletion bridge/core/html/parser/html_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HTMLParser {
private:
ExecutingContext* context_;
static void traverseHTML(Node* root, GumboNode* node);
static void parseProperty(Element* element, GumboElement* gumboElement, bool* is_wbc_scripts_element);
static void parseProperty(Element* element, GumboElement* gumboElement, bool* is_wbc_scripts_element, bool* is_standard_script_element);

static bool parseHTML(const std::string& html, Node* rootNode, bool isHTMLFragment);
};
Expand Down
Binary file modified webf/example/assets/bundle.bhtml
Binary file not shown.
2 changes: 1 addition & 1 deletion webf/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FirstPageState extends State<FirstPage> {
context,
devToolsService: ChromeDevToolsService(),
);
controller.preload(WebFBundle.fromUrl('assets:assets/bundle.html'));
controller.preload(WebFBundle.fromUrl('assets:assets/bundle.bhtml'));
}

@override
Expand Down
3 changes: 1 addition & 2 deletions webf/lib/src/html/script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ class ScriptRunner {
static Future<void> _evaluateScriptBundle(double contextId, WebFBundle bundle, {bool async = false, EvaluateOpItem? profileOp}) async {
// Evaluate bundle.
if (bundle.isJavascript) {
assert(isValidUTF8String(bundle.data!), 'The JavaScript codes should be in UTF-8 encoding format');

bool result;
if (bundle.isRemoteId) {
result = await evaluateScriptsById(contextId, bundle.scriptId!, profileOp: profileOp);
} else {
assert(isValidUTF8String(bundle.data!), 'The JavaScript codes should be in UTF-8 encoding format');
result = await evaluateScripts(contextId, bundle.data!, url: bundle.url, cacheKey: bundle.cacheKey, profileOp: profileOp);
}
if (!result) {
Expand Down

0 comments on commit 21cbb0f

Please sign in to comment.