Skip to content

Commit 7f7a70b

Browse files
triniwizNathanWalker
authored andcommitted
feat: URL & URLSearchParams
1 parent 3894959 commit 7f7a70b

File tree

11 files changed

+23894
-1
lines changed

11 files changed

+23894
-1
lines changed

test-app/app/src/main/assets/app/mainpage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ require("./tests/testPackagePrivate");
6969
require("./tests/kotlin/properties/testPropertiesSupport.js");
7070
require('./tests/testNativeTimers');
7171
require("./tests/testPostFrameCallback");
72-
require("./tests/console/logTests.js");
72+
require("./tests/console/logTests.js");
73+
require('./tests/testURLImpl.js');
74+
require('./tests/testURLSearchParamsImpl.js');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe("Test URLImpl ", function () {
2+
3+
it("Test invalid URL parsing", function(){
4+
var exceptionCaught = false;
5+
try {
6+
const url = new URLImpl('');
7+
}catch(e){
8+
exceptionCaught = true;
9+
}
10+
expect(exceptionCaught).toBe(true);
11+
});
12+
13+
it("Test valid URL parsing", function(){
14+
var exceptionCaught = false;
15+
try {
16+
const url = new URLImpl('https://google.com');
17+
}catch(e){
18+
exceptionCaught = true;
19+
}
20+
expect(exceptionCaught).toBe(false);
21+
});
22+
23+
24+
it("Test URL fields", function(){
25+
var exceptionCaught = false;
26+
const url = new URLImpl('https://google.com');
27+
expect(url.protocol).toBe('https:');
28+
expect(url.hostname).toBe('google.com');
29+
});
30+
31+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
describe("Test URLSearchParamsImpl ", function () {
2+
3+
4+
it("Test URLSearchParamsImpl keys", function(){
5+
const params = new URLSearchParamsImpl("foo=1&bar=2");
6+
const keys = params.keys();
7+
expect(keys[0]).toBe("foo");
8+
expect(keys[1]).toBe("bar");
9+
});
10+
11+
it("Test URLSearchParamsImpl values", function(){
12+
const params = new URLSearchParamsImpl("foo=1&bar=2");
13+
const values = params.values();
14+
expect(values[0]).toBe("1");
15+
expect(values[1]).toBe("2");
16+
});
17+
18+
19+
it("Test URLSearchParamsImpl entries", function(){
20+
const params = new URLSearchParamsImpl("foo=1&bar=2");
21+
const entries = params.entries();
22+
expect(entries[0][0]).toBe("foo");
23+
expect(entries[0][1]).toBe("1");
24+
25+
expect(entries[1][0]).toBe("bar");
26+
expect(entries[1][1]).toBe("2");
27+
28+
});
29+
30+
31+
it("Test URLSearchParamsImpl size", function(){
32+
const params = new URLSearchParamsImpl("foo=1&bar=2");
33+
expect(params.size).toBe(2);
34+
});
35+
36+
it("Test URLSearchParamsImpl append", function(){
37+
const params = new URLSearchParamsImpl("foo=1&bar=2");
38+
params.append("first", "Osei");
39+
expect(params.get("first")).toBe("Osei");
40+
});
41+
42+
43+
it("Test URLSearchParamsImpl delete", function(){
44+
const params = new URLSearchParamsImpl("foo=1&bar=2");
45+
params.append("first", "Osei");
46+
params.delete("first");
47+
expect(params.get("first")).toBe(undefined);
48+
});
49+
50+
51+
it("Test URLSearchParamsImpl has", function(){
52+
const params = new URLSearchParamsImpl("foo=1&bar=2");
53+
expect(params.has("foo")).toBe(true);
54+
});
55+
56+
});

test-app/runtime/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ include_directories(
5252
src/main/cpp
5353
src/main/cpp/include
5454
src/main/cpp/v8_inspector
55+
src/main/cpp/ada
5556
)
5657

5758
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
@@ -137,6 +138,9 @@ add_library(
137138
src/main/cpp/conversions/objects/JSToJavaObjectsConverter.cpp
138139
src/main/cpp/conversions/arrays/JSToJavaArraysConverter.cpp
139140
src/main/cpp/conversions/primitives/JSToJavaPrimitivesConverter.cpp
141+
src/main/cpp/ada/ada.cpp
142+
src/main/cpp/URLImpl.cpp
143+
src/main/cpp/URLSearchParamsImpl.cpp
140144

141145
# V8 inspector source files will be included only in Release mode
142146
${INSPECTOR_SOURCES}

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#ifdef APPLICATION_IN_DEBUG
3636
// #include "NetworkDomainCallbackHandlers.h"
3737
#include "JsV8InspectorClient.h"
38+
#include "URLImpl.h"
39+
#include "URLSearchParamsImpl.h"
40+
3841
#endif
3942

4043
using namespace v8;
@@ -519,6 +522,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
519522
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runOnMainThread"), FunctionTemplate::New(isolate, CallbackHandlers::RunOnMainThreadCallback));
520523
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__postFrameCallback"), FunctionTemplate::New(isolate, CallbackHandlers::PostFrameCallback));
521524
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__removeFrameCallback"), FunctionTemplate::New(isolate, CallbackHandlers::RemoveFrameCallback));
525+
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "URLImpl"), URLImpl::GetCtor(isolate));
526+
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "URLSearchParamsImpl"), URLSearchParamsImpl::GetCtor(isolate));
527+
522528
/*
523529
* Attach `Worker` object constructor only to the main thread (isolate)'s global object
524530
* Workers should not be created from within other Workers, for now

0 commit comments

Comments
 (0)