-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
291 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include "event_target.h" | ||
|
||
NAMESPACE_HTML5_BEGIN; | ||
|
||
class Blob; | ||
class File; | ||
class ArrayBuffer; | ||
|
||
class FileReader : public EventTarget { | ||
public: | ||
struct { | ||
FileReader &self; | ||
operator ArrayBuffer *() { return self.resultArrayBuffer(); }; | ||
operator std::string () { return self.resultString(); }; | ||
} result{*this}; | ||
HTML5_EVENT_HANDLER_PROPERTY(FileReader, EventHandler, onload); | ||
|
||
FileReader(emscripten::val v); | ||
virtual ~FileReader(); | ||
static FileReader *create(); | ||
void abort(); | ||
void readAsArrayBuffer(Blob *blob); | ||
void readAsArrayBuffer(File *file); | ||
void readAsBinaryString(Blob *blob); | ||
void readAsBinaryString(File *file); | ||
void readAsDataURL(Blob *blob); | ||
void readAsDataURL(File *file); | ||
void readAsText(Blob *blob, const std::string &encoding = "utf-8"); | ||
void readAsText(File *file, const std::string &encoding = "utf-8"); | ||
|
||
ArrayBuffer *resultArrayBuffer() const; | ||
std::string resultString() const; | ||
}; | ||
|
||
NAMESPACE_HTML5_END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "libhtml5.h" | ||
|
||
NAMESPACE_HTML5_BEGIN; | ||
|
||
class Headers; | ||
class ReadableStream; | ||
|
||
class Response : public Object { | ||
public: | ||
|
||
HTML5_READONLY_PROPERTY_OBJECT(Response, Headers, headers); | ||
HTML5_READONLY_PROPERTY(Response, bool, ok); | ||
HTML5_READONLY_PROPERTY(Response, bool, redirected); | ||
HTML5_READONLY_PROPERTY(Response, int, status); | ||
HTML5_READONLY_PROPERTY(Response, std::string, type); | ||
HTML5_READONLY_PROPERTY(Response, std::string, url); | ||
HTML5_PROPERTY(Response, bool, useFinalURL); | ||
HTML5_READONLY_PROPERTY_OBJECT(Response, ReadableStream, body); | ||
HTML5_READONLY_PROPERTY(Response, bool, bodyUsed); | ||
|
||
Response(emscripten::val v); | ||
virtual ~Response(); | ||
static Response *create(emscripten::val v); | ||
Response *clone(); | ||
Response *error(); | ||
Response *redirect(const std::string &url, int status = 0); | ||
Promise *arrayBuffer(); | ||
Promise *blob(); | ||
Promise *formData(); | ||
Promise *json(); | ||
Promise *text(); | ||
}; | ||
|
||
NAMESPACE_HTML5_END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "file_reader.h" | ||
#include "blob.h" | ||
#include "array_buffer.h" | ||
|
||
USING_NAMESPACE_HTML5; | ||
|
||
HTML5_BIND_CLASS(FileReader); | ||
|
||
FileReader::FileReader(emscripten::val v) : | ||
EventTarget(v) | ||
{ | ||
} | ||
|
||
FileReader::~FileReader() | ||
{ | ||
} | ||
|
||
FileReader *FileReader::create() | ||
{ | ||
auto reader = new FileReader(HTML5_NEW_PRIMITIVE_INSTANCE(FileReader)); | ||
reader->autorelease(); | ||
return reader; | ||
} | ||
|
||
void FileReader::abort() | ||
{ | ||
HTML5_CALL(this->v, abort); | ||
} | ||
|
||
void FileReader::readAsArrayBuffer(Blob *blob) | ||
{ | ||
HTML5_CALL(this->v, readAsArrayBuffer, blob->v); | ||
} | ||
|
||
void FileReader::readAsArrayBuffer(File *file) | ||
{ | ||
// HTML5_CALL(this->v, readAsArrayBuffer, file->v); | ||
} | ||
|
||
void FileReader::readAsBinaryString(Blob *blob) | ||
{ | ||
HTML5_CALL(this->v, readAsBinaryString, blob->v); | ||
} | ||
|
||
void FileReader::readAsBinaryString(File *file) | ||
{ | ||
//HTML5_CALL(this->v, readAsBinaryString, file->v); | ||
} | ||
|
||
void FileReader::readAsDataURL(Blob *blob) | ||
{ | ||
HTML5_CALL(this->v, readAsDataURL, blob->v); | ||
} | ||
|
||
void FileReader::readAsDataURL(File *file) | ||
{ | ||
//HTML5_CALL(this->v, readAsDataURL, file->v); | ||
} | ||
|
||
void FileReader::readAsText(Blob *blob, const std::string &encoding) | ||
{ | ||
HTML5_CALL(this->v, readAsText, blob->v, encoding); | ||
} | ||
|
||
void FileReader::readAsText(File *file, const std::string &encoding) | ||
{ | ||
//HTML5_CALL(this->v, readAsText, file->v, encoding); | ||
} | ||
|
||
ArrayBuffer *FileReader::resultArrayBuffer() const | ||
{ | ||
return ArrayBuffer::create(this->v["result"]); | ||
} | ||
|
||
std::string FileReader::resultString() const | ||
{ | ||
return this->v["result"].as<std::string>(); | ||
} | ||
|
||
HTML5_EVENT_HANDLER_PROPERTY_IMPL_NEW(FileReader, EventHandler, onload); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "response.h" | ||
#include "promise.h" | ||
|
||
USING_NAMESPACE_HTML5; | ||
|
||
Response::Response(emscripten::val v) : | ||
Object(v) | ||
{ | ||
} | ||
|
||
Response::~Response() | ||
{ | ||
} | ||
|
||
Response *Response::create(emscripten::val v) | ||
{ | ||
auto response = new Response(v); | ||
response->autorelease(); | ||
return response; | ||
} | ||
|
||
Response *Response::clone() | ||
{ | ||
return Response::create(HTML5_CALLv(this->v, clone)); | ||
} | ||
|
||
Response *Response::error() | ||
{ | ||
return Response::create(HTML5_CALLv(this->v, error)); | ||
} | ||
|
||
Response *Response::redirect(const std::string &url, int status) | ||
{ | ||
return Response::create(HTML5_CALLv(this->v, redirect, url, status)); | ||
} | ||
|
||
Promise *Response::arrayBuffer() | ||
{ | ||
return Promise::create(HTML5_CALLv(this->v, arrayBuffer)); | ||
} | ||
|
||
Promise *Response::blob() | ||
{ | ||
return Promise::create(HTML5_CALLv(this->v, blob)); | ||
} | ||
|
||
Promise *Response::formData() | ||
{ | ||
return Promise::create(HTML5_CALLv(this->v, formData)); | ||
} | ||
|
||
Promise *Response::json() | ||
{ | ||
return Promise::create(HTML5_CALLv(this->v, json)); | ||
} | ||
|
||
Promise *Response::text() | ||
{ | ||
return Promise::create(HTML5_CALLv(this->v, text)); | ||
} | ||
|
||
//HTML5_READONLY_PROPERTY_OBJECT_IMPL(Response, Headers, headers); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, bool, ok); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, bool, redirected); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, int, status); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, std::string, type); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, std::string, url); | ||
HTML5_PROPERTY_IMPL(Response, bool, useFinalURL); | ||
//HTML5_READONLY_PROPERTY_OBJECT_IMPL(Response, ReadableStream, body); | ||
HTML5_READONLY_PROPERTY_IMPL(Response, bool, bodyUsed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters