Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Nov 8, 2024
1 parent 39c67e8 commit 2d1ad31
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 92 deletions.
34 changes: 0 additions & 34 deletions packages/patchs/quickjs-2024-01-13/quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5632,16 +5632,6 @@ static void remove_gc_object(JSGCObjectHeader *h)
list_del(&h->link);
}

JS_BOOL JS_IsMarked(JSContext *ctx, JSValueConst v)
{
if (JS_IsObject(v)) {
JSGCObjectHeader *p = JS_VALUE_GET_PTR(v);
return p->mark == 1;
} else {
return FALSE;
}
}

void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
if (JS_VALUE_HAS_REF_COUNT(val)) {
Expand Down Expand Up @@ -5910,30 +5900,6 @@ BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj)
return !p->free_mark;
}

void JS_MarkValueDefault(JSRuntime *rt, JSValueConst val)
{
if (JS_VALUE_HAS_REF_COUNT(val)) {
switch(JS_VALUE_GET_TAG(val)) {
case JS_TAG_OBJECT:
case JS_TAG_FUNCTION_BYTECODE:
{
JSGCObjectHeader *p = JS_VALUE_GET_PTR(val);
assert(p->mark == 0);
mark_children(rt, p, gc_decref_child);
p->mark = 1;
if (p->ref_count == 0) {
list_del(&p->link);
list_add_tail(&p->link, &rt->tmp_obj_list);
}
}
break;
default:
break;
}
}
}


/* Compute memory used by various object types */
/* XXX: poor man's approach to handling multiply referenced objects */
typedef struct JSMemoryUsage_helper {
Expand Down
2 changes: 0 additions & 2 deletions packages/patchs/quickjs-2024-01-13/quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ void *JS_GetRuntimeOpaque(JSRuntime *rt);
void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque);
typedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp);
void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func);
void JS_MarkValueDefault(JSRuntime *rt, JSValueConst val);
void JS_RunGC(JSRuntime *rt);
JS_BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj);

Expand Down Expand Up @@ -631,7 +630,6 @@ static inline JS_BOOL JS_IsObject(JSValueConst v)
return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;
}

JS_BOOL JS_IsMarked(JSContext *ctx, JSValueConst v);
JSValue JS_Throw(JSContext *ctx, JSValue obj);
JSValue JS_GetException(JSContext *ctx);
int JS_HasException(JSContext *ctx);
Expand Down
34 changes: 0 additions & 34 deletions packages/patchs/quickjs-2024-01-13/quickjs_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -5590,16 +5590,6 @@ static void remove_gc_object(JSGCObjectHeader *h)
list_del(&h->link);
}

JS_BOOL JS_IsMarked(JSContext *ctx, JSValueConst v)
{
if (JS_IsObject(v)) {
JSGCObjectHeader *p = JS_VALUE_GET_PTR(v);
return p->mark == 1;
} else {
return FALSE;
}
}

void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
if (JS_VALUE_HAS_REF_COUNT(val)) {
Expand Down Expand Up @@ -5868,30 +5858,6 @@ BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj)
return !p->free_mark;
}

void JS_MarkValueDefault(JSRuntime *rt, JSValueConst val)
{
if (JS_VALUE_HAS_REF_COUNT(val)) {
switch(JS_VALUE_GET_TAG(val)) {
case JS_TAG_OBJECT:
case JS_TAG_FUNCTION_BYTECODE:
{
JSGCObjectHeader *p = JS_VALUE_GET_PTR(val);
assert(p->mark == 0);
mark_children(rt, p, gc_decref_child);
p->mark = 1;
if (p->ref_count == 0) {
list_del(&p->link);
list_add_tail(&p->link, &rt->tmp_obj_list);
}
}
break;
default:
break;
}
}
}


/* Compute memory used by various object types */
/* XXX: poor man's approach to handling multiply referenced objects */
typedef struct JSMemoryUsage_helper {
Expand Down
66 changes: 66 additions & 0 deletions src/webcore/bindings/qjs/QJSNodeFilterCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2024 Zhang Ji Peng All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "config.h"
#include "QJSNodeFilterCondition.h"

#include "Document.h"
#include "Frame.h"
#include "QJSNode.h"
#include "QJSNodeFilter.h"
#include "NodeFilter.h"

#include "qjs_script.h"

namespace WebCore {

JSNodeFilterCondition::JSNodeFilterCondition(JSContext* ctx, JSValue filter)
: m_context(ctx)
, m_filter(JS_DupValue(ctx, filter))
{
}

void JSNodeFilterCondition::mark()
{
JS_FreeValue(m_context, m_filter);
}

short JSNodeFilterCondition::acceptNode(Node* filterNode) const
{
Node* node = filterNode;
Frame* frame = node->document()->frame();
ScriptController* controller = frame->script();
if (controller) {
JSContext* ctx = controller->context();
JSValue argv = toJS(ctx, node);

JSValue protoType = JS_GetPrototype(ctx, m_filter);
JSValue method = JS_GetPropertyStr(ctx, protoType, "acceptNode");

JSValue result = JS_Call(ctx, method, m_filter, 1, &argv);
JS_FreeValue(ctx, protoType);
JS_FreeValue(ctx, method);
return QJS::valueToInt32(ctx, result);
}

return NodeFilter::FILTER_REJECT;
}

} // namespace WebCore
44 changes: 44 additions & 0 deletions src/webcore/bindings/qjs/QJSNodeFilterCondition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2007 Apple Inc. All rights reserved.
* Copyright (C) 2024 Zhang Ji Peng All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _JSNodeFilterCondition_H_
#define _JSNodeFilterCondition_H_

#include "NodeFilterCondition.h"
#include "qjs_dom.h"

namespace WebCore {

class Node;

class JSNodeFilterCondition : public NodeFilterCondition {
public:
JSNodeFilterCondition(JSContext* ctx, JSValue filter);
virtual short acceptNode(Node*) const;
virtual void mark();

protected:
JSContext* m_context;
JSValue m_filter;
};

} // namespace WebCore

#endif // _JSNodeFilterCondition_H_
26 changes: 6 additions & 20 deletions src/webcore/bindings/qjs/qjs_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "RangeException.h"
#include "XMLHttpRequest.h"
#include "QJSNode.h"
#include "QJSDOMWindow.h"

#include <text/String.h>
#include "qjs_dom.h"
Expand Down Expand Up @@ -131,26 +132,6 @@ void ScriptInterpreter::forgetAllDOMNodesForDocument(Document* document)
}
}

void ScriptInterpreter::markDOMNodesForDocument(Document* doc)
{
NodePerDocMap::iterator dictIt = domNodesPerDocument()->find(doc);
if (dictIt != domNodesPerDocument()->end()) {
NodeMap* nodeDict = dictIt->second;
NodeMap::iterator nodeEnd = nodeDict->end();
for (NodeMap::iterator nodeIt = nodeDict->begin(); nodeIt != nodeEnd; ++nodeIt) {
JSValue node = nodeIt->second;
// don't mark wrappers for nodes that are no longer in the
// document - they should not be saved if the node is not
// otherwise reachable from JS.
Node* impl = (Node*)JS_GetOpaque(node, JSNode::js_class_id);
Frame * mainFrame = doc->frame()->page()->mainFrame();
ScriptController* script = mainFrame->script();
if (impl->inDocument() && !JS_IsMarked(script->context(), node))
JS_MarkValueDefault(JS_GetRuntime(script->context()), node);
}
}
}

JSValue ScriptInterpreter::globalObject() const
{
// we need to make sure that any script execution happening in this
Expand All @@ -159,6 +140,11 @@ JSValue ScriptInterpreter::globalObject() const
return m_globalObject;
}

void* ScriptInterpreter::globalObjectData() const
{
return JS_GetOpaque(globalObject(), JSDOMWindow::js_class_id);
}

void ScriptInterpreter::updateDOMNodeDocument(Node* node, Document* oldDoc, Document* newDoc)
{
ASSERT(oldDoc != newDoc);
Expand Down
1 change: 0 additions & 1 deletion src/webcore/bindings/qjs/qjs_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace QJS {
static void forgetDOMNodeForDocument(WebCore::Document*, WebCore::Node*);
static void forgetAllDOMNodesForDocument(WebCore::Document*);
static void updateDOMNodeDocument(WebCore::Node*, WebCore::Document* oldDoc, WebCore::Document* newDoc);
static void markDOMNodesForDocument(WebCore::Document*);

WebCore::Frame* frame() const { return m_frame; }

Expand Down
2 changes: 1 addition & 1 deletion src/webcore/bindings/qjs/qjs_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ScriptController {
#endif
void finishedWithEvent(Event*);

JSContext *context();
JSContext *context(void) const { return m_context; }

QJS::ScriptInterpreter* interpreter();

Expand Down

0 comments on commit 2d1ad31

Please sign in to comment.