Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;

const log = @import("log.zig");
const Http = @import("http/Http.zig");
const Platform = @import("runtime/js.zig").Platform;
const Platform = @import("browser/js/js.zig").Platform;

const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
const Notification = @import("notification.zig").Notification;
Expand Down
10 changes: 5 additions & 5 deletions src/browser/ScriptManager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

const std = @import("std");

const js = @import("js/js.zig");
const log = @import("../log.zig");
const parser = @import("netsurf.zig");

const Env = @import("env.zig").Env;
const Page = @import("page.zig").Page;
const DataURI = @import("DataURI.zig");
const Http = @import("../http/Http.zig");
Expand Down Expand Up @@ -627,7 +627,7 @@ const Script = struct {

const Callback = union(enum) {
string: []const u8,
function: Env.Function,
function: js.Function,
};

const Source = union(enum) {
Expand Down Expand Up @@ -664,7 +664,7 @@ const Script = struct {
});

const js_context = page.main_context;
var try_catch: Env.TryCatch = undefined;
var try_catch: js.TryCatch = undefined;
try_catch.init(js_context);
defer try_catch.deinit();

Expand Down Expand Up @@ -706,7 +706,7 @@ const Script = struct {

switch (callback) {
.string => |str| {
var try_catch: Env.TryCatch = undefined;
var try_catch: js.TryCatch = undefined;
try_catch.init(page.main_context);
defer try_catch.deinit();

Expand All @@ -728,7 +728,7 @@ const Script = struct {
};
defer parser.eventDestroy(loadevt);

var result: Env.Function.Result = undefined;
var result: js.Function.Result = undefined;
const iface = Event.toInterface(loadevt);
f.tryCall(void, .{iface}, &result) catch {
log.warn(.user_script, "script callback", .{
Expand Down
8 changes: 4 additions & 4 deletions src/browser/State.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
// this quickly proved necessary, since different fields are needed on the same
// data at different levels of the prototype chain. This isn't memory efficient.

const Env = @import("env.zig").Env;
const js = @import("js/js.zig");
const parser = @import("netsurf.zig");
const DataSet = @import("html/DataSet.zig");
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
const StyleSheet = @import("cssom/StyleSheet.zig");
const CSSStyleDeclaration = @import("cssom/CSSStyleDeclaration.zig");

// for HTMLScript (but probably needs to be added to more)
onload: ?Env.Function = null,
onerror: ?Env.Function = null,
onload: ?js.Function = null,
onerror: ?js.Function = null,

// for HTMLElement
style: CSSStyleDeclaration = .empty,
Expand All @@ -53,7 +53,7 @@ style_sheet: ?*StyleSheet = null,

// for dom/document
active_element: ?*parser.Element = null,
adopted_style_sheets: ?Env.JsObject = null,
adopted_style_sheets: ?js.JsObject = null,

// for HTMLSelectElement
// By default, if no option is explicitly selected, the first option should
Expand Down
6 changes: 3 additions & 3 deletions src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;

const js = @import("js/js.zig");
const State = @import("State.zig");
const Env = @import("env.zig").Env;
const App = @import("../app.zig").App;
const Session = @import("session.zig").Session;
const Notification = @import("../notification.zig").Notification;
Expand All @@ -34,7 +34,7 @@ const HttpClient = @import("../http/Client.zig");
// You can create multiple browser instances.
// A browser contains only one session.
pub const Browser = struct {
env: *Env,
env: *js.Env,
app: *App,
session: ?Session,
allocator: Allocator,
Expand All @@ -48,7 +48,7 @@ pub const Browser = struct {
pub fn init(app: *App) !Browser {
const allocator = app.allocator;

const env = try Env.init(allocator, &app.platform, .{});
const env = try js.Env.init(allocator, &app.platform, .{});
errdefer env.deinit();

const notification = try Notification.init(allocator, app.notification);
Expand Down
18 changes: 9 additions & 9 deletions src/browser/console/console.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,47 @@ const std = @import("std");
const builtin = @import("builtin");
const log = @import("../../log.zig");

const js = @import("../js/js.zig");
const Page = @import("../page.zig").Page;
const JsObject = @import("../env.zig").Env.JsObject;

pub const Console = struct {
// TODO: configurable writer
timers: std.StringHashMapUnmanaged(u32) = .{},
counts: std.StringHashMapUnmanaged(u32) = .{},

pub fn _lp(values: []JsObject, page: *Page) !void {
pub fn _lp(values: []js.JsObject, page: *Page) !void {
if (values.len == 0) {
return;
}
log.fatal(.console, "lightpanda", .{ .args = try serializeValues(values, page) });
}

pub fn _log(values: []JsObject, page: *Page) !void {
pub fn _log(values: []js.JsObject, page: *Page) !void {
if (values.len == 0) {
return;
}
log.info(.console, "info", .{ .args = try serializeValues(values, page) });
}

pub fn _info(values: []JsObject, page: *Page) !void {
pub fn _info(values: []js.JsObject, page: *Page) !void {
return _log(values, page);
}

pub fn _debug(values: []JsObject, page: *Page) !void {
pub fn _debug(values: []js.JsObject, page: *Page) !void {
if (values.len == 0) {
return;
}
log.debug(.console, "debug", .{ .args = try serializeValues(values, page) });
}

pub fn _warn(values: []JsObject, page: *Page) !void {
pub fn _warn(values: []js.JsObject, page: *Page) !void {
if (values.len == 0) {
return;
}
log.warn(.console, "warn", .{ .args = try serializeValues(values, page) });
}

pub fn _error(values: []JsObject, page: *Page) !void {
pub fn _error(values: []js.JsObject, page: *Page) !void {
if (values.len == 0) {
return;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ pub const Console = struct {
log.warn(.console, "timer stop", .{ .label = label, .elapsed = elapsed - kv.value });
}

pub fn _assert(assertion: JsObject, values: []JsObject, page: *Page) !void {
pub fn _assert(assertion: js.JsObject, values: []js.JsObject, page: *Page) !void {
if (assertion.isTruthy()) {
return;
}
Expand All @@ -143,7 +143,7 @@ pub const Console = struct {
log.info(.console, "assertion failed", .{ .values = serialized_values });
}

fn serializeValues(values: []JsObject, page: *Page) ![]const u8 {
fn serializeValues(values: []js.JsObject, page: *Page) ![]const u8 {
if (values.len == 0) {
return "";
}
Expand Down
4 changes: 2 additions & 2 deletions src/browser/crypto/crypto.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

const std = @import("std");
const Env = @import("../env.zig").Env;
const js = @import("../js/js.zig");
const uuidv4 = @import("../../id.zig").uuidv4;

// https://w3c.github.io/webcrypto/#crypto-interface
pub const Crypto = struct {
_not_empty: bool = true,

pub fn _getRandomValues(_: *const Crypto, js_obj: Env.JsObject) !Env.JsObject {
pub fn _getRandomValues(_: *const Crypto, js_obj: js.JsObject) !js.JsObject {
var into = try js_obj.toZig(Crypto, "getRandomValues", RandomValues);
const buf = into.asBuffer();
if (buf.len > 65_536) {
Expand Down
4 changes: 2 additions & 2 deletions src/browser/cssom/CSSStyleSheet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

const std = @import("std");

const Env = @import("../env.zig").Env;
const js = @import("../js/js.zig");
const Page = @import("../page.zig").Page;
const StyleSheet = @import("StyleSheet.zig");
const CSSRuleList = @import("CSSRuleList.zig");
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn _deleteRule(self: *CSSStyleSheet, index: usize) !void {
_ = self.css_rules.list.orderedRemove(index);
}

pub fn _replace(self: *CSSStyleSheet, text: []const u8, page: *Page) !Env.Promise {
pub fn _replace(self: *CSSStyleSheet, text: []const u8, page: *Page) !js.Promise {
_ = self;
_ = text;
// TODO: clear self.css_rules
Expand Down
26 changes: 12 additions & 14 deletions src/browser/dom/Animation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

const std = @import("std");

const js = @import("../js/js.zig");
const Page = @import("../page.zig").Page;
const JsObject = @import("../env.zig").JsObject;
const Promise = @import("../env.zig").Promise;
const PromiseResolver = @import("../env.zig").PromiseResolver;

const Animation = @This();

effect: ?JsObject,
timeline: ?JsObject,
ready_resolver: ?PromiseResolver,
finished_resolver: ?PromiseResolver,
effect: ?js.JsObject,
timeline: ?js.JsObject,
ready_resolver: ?js.PromiseResolver,
finished_resolver: ?js.PromiseResolver,

pub fn constructor(effect: ?JsObject, timeline: ?JsObject) !Animation {
pub fn constructor(effect: ?js.JsObject, timeline: ?js.JsObject) !Animation {
return .{
.effect = if (effect) |eo| try eo.persist() else null,
.timeline = if (timeline) |to| try to.persist() else null,
Expand All @@ -49,7 +47,7 @@ pub fn get_pending(self: *const Animation) bool {
return false;
}

pub fn get_finished(self: *Animation, page: *Page) !Promise {
pub fn get_finished(self: *Animation, page: *Page) !js.Promise {
if (self.finished_resolver == null) {
const resolver = page.main_context.createPromiseResolver();
try resolver.resolve(self);
Expand All @@ -58,7 +56,7 @@ pub fn get_finished(self: *Animation, page: *Page) !Promise {
return self.finished_resolver.?.promise();
}

pub fn get_ready(self: *Animation, page: *Page) !Promise {
pub fn get_ready(self: *Animation, page: *Page) !js.Promise {
// never resolved, because we're always "finished"
if (self.ready_resolver == null) {
const resolver = page.main_context.createPromiseResolver();
Expand All @@ -67,19 +65,19 @@ pub fn get_ready(self: *Animation, page: *Page) !Promise {
return self.ready_resolver.?.promise();
}

pub fn get_effect(self: *const Animation) ?JsObject {
pub fn get_effect(self: *const Animation) ?js.JsObject {
return self.effect;
}

pub fn set_effect(self: *Animation, effect: JsObject) !void {
pub fn set_effect(self: *Animation, effect: js.JsObject) !void {
self.effect = try effect.persist();
}

pub fn get_timeline(self: *const Animation) ?JsObject {
pub fn get_timeline(self: *const Animation) ?js.JsObject {
return self.timeline;
}

pub fn set_timeline(self: *Animation, timeline: JsObject) !void {
pub fn set_timeline(self: *Animation, timeline: js.JsObject) !void {
self.timeline = try timeline.persist();
}

Expand Down
Loading