Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Oct 18, 2024
1 parent 515c6b7 commit 137aa34
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/text/String.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

#include "../webcore/platform/CString.h"
#include "../webcore/platform/PlatformString.h"
23 changes: 19 additions & 4 deletions src/webcore/bindings/qjs/qjs_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ namespace QJS {
};
#endif

JSValue jsStringOrNull(const WebCore::String&); // null if the string is null
JSValue jsStringOrUndefined(const WebCore::String&); // undefined if the string is null
JSValue jsStringOrFalse(const WebCore::String&); // boolean false if the string is null
JSValue jsStringOrNull(JSContext*, const WebCore::String&); // null if the string is null
JSValue jsStringOrUndefined(JSContext*, const WebCore::String&); // undefined if the string is null
JSValue jsStringOrFalse(JSContext*, const WebCore::String&); // boolean false if the string is null

// see JavaScriptCore for explanation should be used for UString that is already owned
// by another object, so that collecting the JSString wrapper is unlikely to save memory.
Expand All @@ -170,9 +170,24 @@ namespace QJS {

WebCore::String valueToStringWithNullCheck(JSContext*, JSValue); // null String if the value is null
WebCore::String valueToStringWithUndefinedOrNullCheck(JSContext*, JSValue); // null String if the value is null or undefined
WebCore::String valueToString(JSContext*, JSValue);
int32_t valueToInt32(JSContext*, JSValue, bool& ok);
int32_t valueToInt32(JSContext*, JSValue);
float valueToFloat(JSContext*, JSValue);
double valueToDouble(JSContext*, JSValue);
bool valueToBoolean(JSContext*, JSValue);

template <typename T> inline JSValue toJS(JSContext* ctx, PassRefPtr<T> ptr) { return toJS(ctx, ptr.get()); }

} // namespace

template <typename T> inline T* getPtr(const PassRefPtr<T>& p)
{
return p.get();
}

template <typename T> inline T* getPtr(T* p)
{
return p;
}
} // namespace
#endif
22 changes: 7 additions & 15 deletions src/webcore/bindings/qjs/qjs_css.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,23 @@
#define kjs_css_h

#include "Color.h"
#include "kjs_binding.h"
#include "qjs_binding.h"

namespace WebCore {

class JSRGBColor : public KJS::DOMObject {
class JSRGBColor {
public:
JSRGBColor(KJS::ExecState*, unsigned color);
~JSRGBColor();
static void init(JSContext*);
static JSValue create(JSContext*, uint32_t color);

virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
// no put - all read-only
static JSValue getValueProperty(JSContext * ctx, JSValueConst this_val, int token);

virtual const KJS::ClassInfo* classInfo() const { return &info; }
static const KJS::ClassInfo info;
static JSClassID js_class_id;

enum { Red, Green, Blue };

unsigned impl() const { return m_color; }

private:
unsigned m_color;
};

KJS::JSValue* getJSRGBColor(KJS::ExecState*, unsigned color);
JSValue getJSRGBColor(JSContext*, uint32_t color);

} // namespace WebCore

Expand Down
10 changes: 5 additions & 5 deletions src/webcore/bindings/qjs/qjs_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef kjs_window_h
#define kjs_window_h
#ifndef qjs_window_h
#define qjs_window_h

#include "PlatformString.h"
#include "kjs_binding.h"
#include "qjs_binding.h"
#include <text/String.h>
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>

Expand Down Expand Up @@ -226,7 +226,7 @@ namespace QJS {
} // namespace

namespace WebCore {
KJS::JSValue* toJS(KJS::ExecState*, DOMWindow*);
JSValue toJS(JSContext*, DOMWindow*);
} // namespace WebCore

#endif
Loading

0 comments on commit 137aa34

Please sign in to comment.