Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit acfd8f5

Browse files
committed
Add interfaced native wrapper for global object
1 parent 6fa457c commit acfd8f5

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <pinepain@gmail.com>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Common;
17+
18+
19+
use Pinepain\JsSandbox\NativeWrappers\NativeObjectWrapper;
20+
21+
22+
class NativeGlobalObjectWrapper extends NativeObjectWrapper implements NativeGlobalObjectWrapperInterface
23+
{
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <pinepain@gmail.com>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Common;
17+
18+
19+
use Pinepain\JsSandbox\NativeWrappers\NativeObjectWrapperInterface;
20+
21+
22+
interface NativeGlobalObjectWrapperInterface extends NativeObjectWrapperInterface
23+
{
24+
}

‎src/Laravel/JsSandboxModulesServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
use Illuminate\Contracts\Container\Container;
2020
use Illuminate\Support\ServiceProvider;
21+
use Pinepain\JsSandbox\Common\NativeGlobalObjectWrapper;
22+
use Pinepain\JsSandbox\Common\NativeGlobalObjectWrapperInterface;
2123
use Pinepain\JsSandbox\Modules\ModulesCache;
2224
use Pinepain\JsSandbox\Modules\ModulesCacheInterface;
2325
use Pinepain\JsSandbox\Modules\ModulesService;
@@ -33,6 +35,7 @@
3335
use Pinepain\JsSandbox\Specs\ObjectSpecsCollectionInterface;
3436
use Pinepain\JsSandbox\Wrappers\WrapperInterface;
3537
use V8\Context;
38+
use V8\Isolate;
3639

3740

3841
class JsSandboxModulesServiceProvider extends ServiceProvider
@@ -67,8 +70,8 @@ public function register()
6770
$app->make(WrapperInterface::class)
6871
);
6972
});
70-
}
7173

74+
}
7275

7376
public function provides()
7477
{
@@ -81,6 +84,7 @@ public function provides()
8184

8285
RequireCallbackInterface::class,
8386
NativeRequireFunctionWrapperInterface::class,
87+
8488
];
8589
}
8690
}

‎src/Laravel/JsSandboxServiceProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Illuminate\Contracts\Container\Container;
2020
use Illuminate\Support\ServiceProvider;
2121
use InvalidArgumentException;
22+
use Pinepain\JsSandbox\Common\NativeGlobalObjectWrapper;
23+
use Pinepain\JsSandbox\Common\NativeGlobalObjectWrapperInterface;
2224
use Pinepain\JsSandbox\Extractors\Extractor;
2325
use Pinepain\JsSandbox\Extractors\ExtractorDefinitionBuilder;
2426
use Pinepain\JsSandbox\Extractors\ExtractorDefinitionBuilderInterface;
@@ -96,6 +98,7 @@ public function register()
9698
$this->registerFunctionCallHandler();
9799
$this->registerWrapper();
98100
$this->registerExtractor();
101+
$this->registerCommon();
99102
}
100103

101104
protected function registerIsolateAndContext()
@@ -251,7 +254,18 @@ protected function registerExtractor()
251254

252255
return $collection;
253256
});
257+
}
254258

259+
public function registerCommon()
260+
{
261+
$this->app->singleton(NativeGlobalObjectWrapperInterface::class, function (Container $app) {
262+
return new NativeGlobalObjectWrapper(
263+
$app->make(Isolate::class),
264+
$app->make(Context::class),
265+
$app->make(Context::class)->globalObject(),
266+
$app->make(WrapperInterface::class)
267+
);
268+
});
255269
}
256270

257271
public function provides()
@@ -284,6 +298,7 @@ public function provides()
284298
ExtractorsObjectStoreInterface::class,
285299
ExtractorInterface::class,
286300

301+
NativeGlobalObjectWrapperInterface::class,
287302
];
288303
}
289304
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /