Skip to content

Commit f14c80e

Browse files
author
Nako Sung
committed
Priviledge problem...
1 parent 9d918c7 commit f14c80e

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

Plugins/UnrealJS/Source/V8/Private/JavascriptIsolate_Private.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Helpers.h"
1212
#include "JavascriptGeneratedClass.h"
1313
#include "StructMemoryInstance.h"
14+
#include "JavascriptMemoryObject.h"
1415

1516
using namespace v8;
1617

@@ -664,6 +665,25 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
664665
Template->PrototypeTemplate()->Set(I.Keyword(name), I.FunctionTemplate(fn));
665666
};
666667

668+
add_fn("access", [](const FunctionCallbackInfo<Value>& info)
669+
{
670+
FIsolateHelper I(info.GetIsolate());
671+
672+
if (info.Length() == 1)
673+
{
674+
auto Source = Cast<UJavascriptMemoryObject>(UObjectFromV8(info[0]));
675+
676+
if (Source)
677+
{
678+
auto ab = ArrayBuffer::New(info.GetIsolate(), Source->GetMemory(), Source->GetSize());
679+
ab->Set(I.Keyword("$source"), info[0]);
680+
info.GetReturnValue().Set(ab);
681+
return;
682+
}
683+
}
684+
I.Throw(TEXT("memory.fork requires JavascriptMemoryObject"));
685+
});
686+
667687
// memory.bind
668688
add_fn("bind", [](const FunctionCallbackInfo<Value>& info)
669689
{
@@ -688,7 +708,21 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
688708
{
689709
FIsolateHelper I(info.GetIsolate());
690710

691-
GCurrentContents = v8::ArrayBuffer::Contents();
711+
if (info.Length() == 1 && info[0]->IsArrayBuffer())
712+
{
713+
auto arr = info[0].As<ArrayBuffer>();
714+
715+
if (arr->IsNeuterable())
716+
{
717+
arr->Neuter();
718+
719+
GCurrentContents = v8::ArrayBuffer::Contents();
720+
}
721+
else
722+
{
723+
I.Throw(TEXT("ArrayBuffer is not neuterable"));
724+
}
725+
}
692726

693727
info.GetReturnValue().Set(info.Holder());
694728
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "JavascriptMemoryObject.generated.h"
4+
5+
/**
6+
*
7+
*/
8+
UCLASS(BlueprintType, Abstract)
9+
class V8_API UJavascriptMemoryObject : public UObject
10+
{
11+
GENERATED_BODY()
12+
13+
public:
14+
virtual void* GetMemory() { return nullptr; }
15+
virtual int32 GetSize() { return 0; }
16+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include "JavascriptMemoryObject.h"
4+
#include "JavascriptSharedMemoryRegion.generated.h"
5+
6+
/**
7+
*
8+
*/
9+
UCLASS(BlueprintType)
10+
class V8_API UJavascriptSharedMemoryRegion : public UJavascriptMemoryObject
11+
{
12+
GENERATED_BODY()
13+
14+
private:
15+
FGenericPlatformMemory::FSharedMemoryRegion* Region{ nullptr };
16+
17+
public:
18+
virtual void BeginDestroy() override;
19+
20+
UFUNCTION(BlueprintCallable, Category = "Javascript")
21+
void Dispose();
22+
23+
virtual void* GetMemory() override;
24+
virtual int32 GetSize() override;
25+
26+
UFUNCTION(BlueprintCallable, Category = "Javascript")
27+
static UJavascriptSharedMemoryRegion* Create(const FName& Name, bool bCreate, bool bRead, bool bWrite, int32 Size);
28+
};

0 commit comments

Comments
 (0)